C语言
时间: 2023-06-21 12:24:39 浏览: 39
好的,下面是使用C语言编写的程序:
```c
#include <stdio.h>
struct Time {
int hour;
int minute;
int second;
};
void displayTime(struct Time t) {
printf("%02d:%02d:%02d\n", t.hour, t.minute, t.second);
}
int main() {
struct Time nowTime, afterTime;
int n;
printf("请输入当前时间(时 分 秒):");
scanf("%d %d %d", &nowTime.hour, &nowTime.minute, &nowTime.second);
printf("请输入要增加的秒数:");
scanf("%d", &n);
int totalSeconds = nowTime.hour * 3600 + nowTime.minute * 60 + nowTime.second + n;
int newHour = totalSeconds / 3600 % 24;
int newMinute = totalSeconds % 3600 / 60;
int newSecond = totalSeconds % 60;
afterTime.hour = newHour;
afterTime.minute = newMinute;
afterTime.second = newSecond;
printf("增加%d秒后的时间为:", n);
displayTime(afterTime);
return 0;
}
```
程序中通过 `struct Time` 结构体类型来表示时间,然后通过输入当前时间和增加的秒数计算出增加后的时间,并输出。同时,如果超过24点,则从0点开始计时。
希望这个程序能够帮到您!
相关推荐
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)