能不能写的简单一点
时间: 2024-02-18 14:59:13 浏览: 29
当然可以,以下是更简单的程序代码:
```c
#include <stdio.h>
struct Time {
int hour;
int minute;
int second;
};
int main() {
struct Time currentTime;
int n;
printf("请输入当前时间(时 分 秒): ");
scanf("%d %d %d", ¤tTime.hour, ¤tTime.minute, ¤tTime.second);
printf("请输入秒数n(n<60): ");
scanf("%d", &n);
// 计算时间
int totalSeconds = currentTime.hour * 3600 + currentTime.minute * 60 + currentTime.second + n;
currentTime.hour = totalSeconds / 3600 % 24;
currentTime.minute = totalSeconds % 3600 / 60;
currentTime.second = totalSeconds % 60;
printf("当前时间为:%02d:%02d:%02d\n", currentTime.hour, currentTime.minute, currentTime.second);
return 0;
}
```
您只需要输入当前时间和秒数n,程序就会计算出n秒后的时间,并以h:m:s的格式输出。如果超过24点,程序将从0点重新开始计时。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)