Note:输出补零
#include<stdio.h>
struct time
{
int h;
int m;
int s;
} t;
int main()
{
int ss;
scanf("%d:%d:%d",&t.h,&t.m,&t.s);
scanf("%d",&ss);
t.s=t.s+ss;
if(t.s>=60)
{
t.s-=60;
t.m+=1;
if(t.m>=60)
{
t.m-=60;
t.h+=1;
if(t.h>=24)
{
t.h-=24;
}
}
}
printf("%02d:%02d:%02d",t.h,t.m,t.s);
return 0;
}
本文介绍了一个简单的C语言程序,该程序实现时间相加的功能,并在输出时对小时、分钟和秒不足两位数的部分进行补零处理,确保输出格式统一。程序首先接收用户输入的初始时间(小时、分钟、秒)及需要增加的秒数,然后计算新的时间并按格式输出。
947

被折叠的 条评论
为什么被折叠?



