Posted on 2007-07-03 17:51
停留的风 阅读(424)
评论(0) 编辑 收藏 所属分类:
C语言学习历程
#include <stdio.h>
struct time
{
int hour;
int minute;
int second;
};
struct time preTime(struct time s1,struct time s2)
{
struct time preTime;
int temp;
int s1_sec=s1.hour*3600+s1.minute*60+s1.second;
int s2_sec=s2.hour*3600+s2.minute*60+s2.second;
int preSec=s1_sec-s2_sec;
if(preSec<0)
{
preSec=-preSec;
}
preTime.second=preSec%60;
temp=preSec/60;
preTime.minute=temp%60;
temp=temp/60;
preTime.hour=temp%24;
return preTime;
}
int main(void)
{
struct time s1={3,45,15};
struct time s2={9,44,03};
struct time pre=preTime(s1,s2);
printf("The first time is %.2i/%.2i/%2i ,the second time is %.2i/%.2i/%.2i.\n",s1.hour,s1.minute,s1.second,s2.hour,s2.minute,s2.second);
printf("The long between the two times is %.2i:%.2i:%.2i.\n",pre.hour,pre.minute,pre.second);
return 0;
}
运行结果: