c语言 制作 倒计时?

Python018

c语言 制作 倒计时?,第1张

#include<stdio.h>#include<time.h>

int main(){ time_t start, end

int i

start = time(NULL)

end = time(NULL)

printf("please input:")

for(i = 0i <3i++){

while(end - start <i){

end = time(NULL)

}

cystem("cls")

printf("%d", i)

}

return 0

}

1、C语言中实现精确计时,参考代码如下:

ANSIC: ftime()

struct timeb {

time_t time

unsigned short millitm

short timezone

short dstflag

}

2、另外,还有就是更精确定计时,需要CPU的支持,具体情况,可以参考MSDN。

LARGE_INTEGER frequency = {0}

LARGE_INTEGER now = {0}

LARGE_INTEGER end = {0}

QueryPerformanceFrequency(&frequency);

while (QueryPerformanceCounter(&now) &&((now.QuadPart - end.QuadPart) <0))

{

Sleep(0)

}