【PTA】5-2 下列程序读入时间数值,将其加1秒后输出,时间格式为:hh: mm: ss,即“小时:分钟:秒”,当小时等于24小时,置为0。

5-2

下列程序读入时间数值,将其加1秒后输出,时间格式为:hh: mm: ss,即“小时:分钟:秒”,当小时等于24小时,置为0。

#include <stdio.h>
struct
{ 
     int hour,minute,second;
}time;
int main(void)
{  
    scanf("%d:%d:%d", &time.hour, &time.minute, &time.second);
    time.second++;
    if(time.second == 60)
	{
        time.minute++; 
        time.second = 0;
        if(time.minute == 60)
		{
			time.hour++; 
			time.minute = 0;
            if( time.hour == 24) 
                 time.hour = 0; 
        }
    }
      printf ("%d:%d:%d\n", time.hour, time.minute, time.second );
      return 0;
}
posted @ 2021-05-11 19:55  ekertree  阅读(368)  评论(0)    收藏  举报