302班

java突击队
posts - 151, comments - 74, trackbacks - 0, articles - 14
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

#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;
}
运行结果:


只有注册用户登录后才能发表评论。


网站导航: