C语言入门代码库,模拟显示数字时钟
#include<stdio.h>int hour, minute, second;void Update() //时钟函数
{second++;if (second == 60) //秒{second = 0;minute++;}if (minute == 60) //分钟{minute = 0;hour++;}if (hour == 0) //小时{hour = 0;}
}void Display() //显示函数
{printf("%2d:%2d:%2d\r", hour, minute, second);
}void Delay() //延时函数
{int t;for (t = 0; t < 100000000; t++); //for循环空语句实现延时
}int main(void)
{int i;hour = minute = second = 0; //时钟初始化for (i = 0; i < 1000000; i++){Update(); //更新时分秒Display(); //显示时分秒Delay(); //延迟时间一秒}return 0;
}