0
点赞
收藏
分享

微信扫一扫

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

巧乐兹_d41f 2022-04-29 阅读 67
c语言

本题要求编写程序,以hh:mm:ss的格式输出某给定时间再过n秒后的时间值(超过23:59:59就从0点开始计时)。

输入格式:

输入在第一行中以hh:mm:ss的格式给出起始时间,第二行给出整秒数n(<60)。

输出格式:

输出在一行中给出hh:mm:ss格式的结果时间。

输入样例:

11:59:40
30

输出样例:

12:00:10

源代码:

#include<stdio.h>
struct time{
	int hour;
	int minute;
	int second;
};
int main()
{
	struct time t;
	int s;
	scanf("%d:%d:%d",&t.hour,&t.minute,&t.second);
	scanf("%d",&s);
	t.second=t.second+s;
	if(t.second>=60){
		t.minute=t.minute+t.second/60;
		t.second=t.second%60;
	}
	if(t.minute>=60){
		t.hour=t.hour+t.minute/60;
		t.minute=t.minute%60;
	}
	if(t.hour>=24){
		t.hour=t.hour%24;
	}
	printf("%.2d:%.2d:%.2d",t.hour,t.minute,t.second);
	return 0;
}

 

举报

相关推荐

0 条评论