Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- typedef struct {
- int hour;
- int minute;
- int second;
- } time;
- int main(void)
- {
- int diff;
- time t1,t2;
- printf("時刻1の時 分 秒を入力 >");
- scanf("%d %d %d",&t1.hour,&t1.minute,&t1.second);
- printf("時刻2の時 分 秒を入力 >");
- scanf("%d %d %d",&t2.hour,&t2.minute,&t2.second);
- diff = (t1.hour - t2.hour) * 3600 + (t1.minute - t2.minute) * 60 + (t1.second - t2.second);
- if(diff < 0) diff += 24 * 3600;
- printf("時間差は%d時間%d分%d秒です。\n", diff/3600,diff%3600/60,diff%60);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment