当前位置:网站首页>Exercise 9-1 time conversion (15 points)

Exercise 9-1 time conversion (15 points)

2022-07-04 09:46:00 skeet follower

This question requires the preparation of procedures , With hh:mm:ss Output in the format of... After a given time n Time value after seconds ( exceed 23:59:59 From 0 The clock starts at ).

Input format :

Enter in the first line with hh:mm:ss The format of gives the start time , The second line gives the number of whole seconds n(<60).

Output format :

The output is given on one line hh:mm:ss Result time in format .

sample input :

11:59:40
30

sample output :

12:00:10

The code is as follows :

#include<stdio.h>
int main()
{
    int hour=0,minute=0,second=0,n;
    scanf("%d:%d:%d",&hour,&minute,&second);
    scanf("%d",&n);
    second+=n;
    if(second>=60){
        minute++;
        second-=60;
    }
    if(minute>=60){
          hour++;
        minute-=60;
    }
    if(hour>=24){
        hour-=24;
    }
    printf("%02d:%02d:%02d",hour,minute,second);
    return 0;
}

原网站

版权声明
本文为[skeet follower]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202141423487715.html