C语言实验计算时间差(小时,分钟,秒,只适用于同一天内)
```c
#include <stdio.h>
int main()
{
int hour1,min1,s1,ss1;
int hour2,min2,s2,ss2;
int hour,min,s;
int minus;
char op1,op2,op3,op4;
scanf("%d%c%d%c%d",&hour1,&op1,&min1,&op2,&s1);
ss1=s1+min1*60+hour1*3600;
scanf("%d%c%d%c%d",&hour2,&op3,&min2,&op4,&s2);
ss2=s2+min2*60+hour2*3600;
if(ss1>ss2)
minus=ss1-ss2;
else
minus=ss2-ss1;
hour=minus/3600;
min=(minus%3600)/60;
s=minus-hour*3600-min*60;
printf("%02d:%02d:%02d",hour,min,s);
return 0;
}
运行说明:输入格式例子12:01:32
别忘记输入:(英文状态)