习题9-1 时间换算

 1 #include <stdio.h>
 2 
 3 struct time
 4 {
 5     int hour;
 6     int minute;
 7     int second;
 8 };
 9 int main(void)
10 {
11     int n, temp;
12     struct time t1;
13 
14     scanf("%d:%d:%d", &t1.hour, &t1.minute, &t1.second);
15     scanf("%d", &n);
16 
17     t1.second = t1.second + n;
18     temp = t1.second / 60;
19     t1.second = t1.second % 60;
20 
21     t1.minute = t1.minute + temp;
22     temp = t1.minute / 60;
23     t1.minute = t1.minute % 60;
24 
25     t1.hour = t1.hour + temp;
26     t1.hour = t1.hour % 24;
27 
28     printf("%02d:%02d:%02d
", t1.hour, t1.minute, t1.second);
29 
30     return 0;
31 }
原文地址:https://www.cnblogs.com/2018jason/p/12100203.html