编写一个C程序判断24小时制任意两个时间点直接的时间差
时间: 2024-05-11 22:14:01 浏览: 41
PTA判断上三角矩阵(C语言)
```c
#include <stdio.h>
int main()
{
int h1, m1, s1, h2, m2, s2, t1, t2, diff;
// 输入第一个时间点的时分秒
printf("Enter the first time (hh:mm:ss): ");
scanf("%d:%d:%d", &h1, &m1, &s1);
// 输入第二个时间点的时分秒
printf("Enter the second time (hh:mm:ss): ");
scanf("%d:%d:%d", &h2, &m2, &s2);
// 将时分秒转换为秒数
t1 = h1 * 3600 + m1 * 60 + s1;
t2 = h2 * 3600 + m2 * 60 + s2;
// 计算时间差
diff = t2 - t1;
// 输出时间差
printf("The time difference is %d seconds.\n", diff);
return 0;
}
```
阅读全文