实现从键盘输入时间,然后输出+1后的时间,比如23:59:59
1 #include <stdio.h>
2
3 int main()
4 {
5 int HH, MM, SS;
6 printf("Input HH:MM:SS\n");
7 scanf("%d:%d:%d",&HH,&MM,&SS);
8 SS++;
9 if (SS == 60){
10 SS = 0;
11 MM ++;
12 }
13 if (MM == 60){
14 MM = 0;
15 HH ++;
16 }
17 if (HH == 24){
18 HH = 0;
19 MM = 0;
20 SS = 0;
21 }
22 printf("Now is %d:%d:%d\n",HH,MM,SS);
23 }
没有做太多的容错判断,只是单纯的对应了一下功能。大概测试了一下,功能正常。