/*此代码的功能实现了计时器的功能*/
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
struct clock {
int second;
int minute;
int hour;
};/*如果你学过C的话,这并不陌生,{结构},但是,进阶了解过cpp的话,{clock类}*/
typedef struct clock CLOCK;
int main() {
CLOCK t = { 0,0,0 };
system("pause");
int n = 100, i = 0;/*n的值也可以改,代表的是循环次数n-1*/
while (++i < n) {
t.second++;
if (t.second >= 60) {
t.second = 0;
t.minute++;
}
if (t.minute >= 60) {
t.minute = 0;
t.hour++;
}
if (t.hour >= 12) {
t.hour = 0;
}/*实现计数的功能,minute,second 实现60进制,hour 实现12进制*/
printf("%2d:%2d:%2d\r",t.hour, t.minute, t.second);
Sleep(1000);/*让cpu休息下,当然你也可以改变数值,具体换算关系是1000ms=1s*/
}
system("pause");
return 0;
}