简单C语言程序
1 #include<stdio.h> 2 3 int main(void) 4 { 5 /* 6 计算两个时间的时间差 7 */ 8 int hour1, minute1; 9 int hour2, minute2; 10 11 printf("请输入第一个时间:"); 12 scanf_s("%d:%d", &hour1, &minute1); 13 printf("请输入第二个时间:"); 14 scanf_s("%d:%d", &hour2, &minute2); 15 16 int t1 = hour1 * 60 + minute1; 17 int t2 = hour2 * 60 + minute2; 18 19 int t = t1 - t2; 20 21 printf("时间差是%d小时%d分钟。\n", t / 60, t % 60); 22 23 return 0; 24 }
1 #include<stdio.h> 2 3 int main(void) 4 { 5 /* 6 计算两个时间的时间差 7 */ 8 int hour1, minute1; 9 int hour2, minute2; 10 11 printf("请输入第一个时间:"); 12 scanf_s("%d:%d", &hour1, &minute1); 13 printf("请输入第二个时间:"); 14 scanf_s("%d:%d", &hour2, &minute2); 15 16 int t1 = 0; 17 int t2 = 0; 18 19 if (minute1 >= minute2) 20 { 21 t1 = hour1 - hour2; 22 t2 = minute1 - minute2; 23 } 24 else 25 { 26 t1 = hour1 - 1 - hour2; 27 t2 = minute1 + 60 - minute2; 28 } 29 30 printf("时间差是%d小时%d分钟。\n", t1, t2); 31 32 return 0; 33 }