#include <stdio.h>
struct time_struct {
int h;
int m;
int s;
};
void cal_time(struct time_struct *t1,struct time_struct *t2);
void main()
{
struct time_struct time1,time2;
printf("Input hour,minute,second of time1: ");
scanf("%d:%d:%d",&time1.h,&time1.m,&time1.s);
printf("Input hour,minute,second of time2: ");
scanf("%d:%d:%d",&time2.h,&time2.m,&time2.s);
cal_time(&time1,&time2);
}
void cal_time(struct time_struct *t1,struct time_struct *t2)
{
int res_h,res_m,res_s,temp;
temp=(t1->h-t2->h)*3600+(t1->m-t2->m)*60+t1->s-t2->s;
if(temp<0)
temp=-temp;
res_h=temp/3600;
temp%=3600;
res_m=temp/60;
res_s=temp%60;
printf("%d:%d:%d\n",res_h,res_m,res_s);
}
Add a comment



指定位置输出字符串
结构指针:计算某日是该年中的第几天







