浙大版《C语言程序设计(第3版)》题目集 习题9-1 时间换算 (15分)

在这里插入图片描述

#include <stdio.h>
struct time
{
    int hour;
    int minute;
    int second;
};
int main()
{
    struct time t;
    int add;
    scanf("%d:%d:%d", &t.hour, &t.minute, &t.second);
    scanf("%d", &add);
    t.second = t.second + add;
    if (t.second >= 60)
    {
        t.minute++;
        t.second = t.second - 60;
    }
    if (t.minute >= 60)
    {
        t.hour++;
        t.minute = t.minute - 60;
    }
    if (t.hour > 23)
    {
        t.hour = t.hour - 24;
    }
    printf("%02d:%02d:%02d", t.hour, t.minute, t.second);
    return 0;
}
发布了252 篇原创文章 · 获赞 117 · 访问量 8547

猜你喜欢

转载自blog.csdn.net/qq_44458489/article/details/105321508