习题9-1 时间换算

习题9-1 时间换算_第1张图片

#include
typedef struct _time{
	int hour;
	int minute;
	int second;
}Time;
Time* timeUpdate(Time *p,int n);
int main(int argc,char const *argv[])
{
	Time now;
	int n;
	scanf("%d:%d:%d",&now.hour,&now.minute,&now.second);
	scanf("%d",&n);
	timeUpdate(&now,n);
	printf("%.2d:%.2d:%.2d\n",now.hour,now.minute,now.second);
	return 0;
}
Time* timeUpdate(Time *p,int n)
{
	p->second += n;
	if( p->second >= 60 ){
		p->minute += p->second/60;
		p->second = p->second%60;
		if( p->minute >= 60 ){
			p->hour += p->minute/60;
			p->minute = p->minute%60;
			if( p->hour >= 24 ){
				p->hour = p->hour%24;
			}
		}
	}
	return p;
}

你可能感兴趣的:(pta)