c语言时钟倒计时
时间: 2023-07-03 13:23:23 浏览: 133
下面是一个简单的 C 语言时钟倒计时的示例代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int main()
{
int hour, minute, second;
printf("请输入倒计时的小时数:");
scanf("%d", &hour);
printf("请输入倒计时的分钟数:");
scanf("%d", &minute);
printf("请输入倒计时的秒数:");
scanf("%d", &second);
int totalSeconds = hour * 3600 + minute * 60 + second;
while (totalSeconds > 0) {
system("cls"); // 清屏
printf("倒计时:%02d:%02d:%02d\n", totalSeconds / 3600, totalSeconds % 3600 / 60, totalSeconds % 60);
Sleep(1000); // 等待1秒
totalSeconds--;
}
printf("时间到!\n");
return 0;
}
```
这个程序会先要求用户输入倒计时的小时数、分钟数和秒数,然后计算出总的秒数,再每秒钟更新一次倒计时的显示,直到倒计时结束。注意,这个程序使用了 Windows.h 头文件中的 Sleep 函数来实现等待一秒钟的功能,如果你在其他操作系统上运行这个程序可能需要换成相应的函数。
阅读全文
相关推荐

















