输入一个时间数值,再输入秒数 n,输出该时间再过 n 秒后的时间值,时间的表示形式为时:分:秒,#include <stdio.h>struct time{ int hour,minute,second;};void timecal(struct time *p,int n);int main(void){ int n;
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/24 08:18:21
输入一个时间数值,再输入秒数 n,输出该时间再过 n 秒后的时间值,时间的表示形式为时:分:秒,#include <stdio.h>struct time{ int hour,minute,second;};void timecal(struct time *p,int n);int main(void){ int n;
输入一个时间数值,再输入秒数 n,输出该时间再过 n 秒后的时间值,时间的表示形式为时:分:秒,
#include <stdio.h>
struct time{
int hour,minute,second;
};
void timecal(struct time *p,int n);
int main(void)
{
int n;
int repeat,ri;
struct time time;
scanf("%d",&repeat);
for(ri = 1; ri <= repeat; ri++){
scanf("%d:%d:%d",&time.hour,&time.minute,&time.second);
scanf("%d",&n);
timecal(&time,n);
printf("time:%d:%d:%d\n",time.hour,time.minute,time.second);
}
void timecal(stuct time*p,int n);
{
if(time.second+n<60)time.second+=n;
else if(time.second+n==60){
time.second=0;
time.minute++;
if(time.minute==60){
time.minute=0;
time.hour++;
if(time.hour==24)
time.hour=0;
}
}
else{
time.second=(n+time.second)%60;
if((time.minute+(time.second+n)/60)<60)
time.minute+=(time.second+n)/60;
else if((time.minute+(time.second+n)/60)==60){
time.minute=0;
time.hour++;
if(time.hour==24)
time.hour=0;
}
else{
time.minute=(time.minute+(time.second+n)/60)%60;
if((time.hour+(time.minute+(time.second+n)/60)/60)<24)time.hour=0;
else time.hour=(time.hour+(time.minute+(time.second+n)/60)/60)%24;
}
}
}
程序有点问题,求修正,另外有木有大神有更简单的程序分享
输入一个时间数值,再输入秒数 n,输出该时间再过 n 秒后的时间值,时间的表示形式为时:分:秒,#include <stdio.h>struct time{ int hour,minute,second;};void timecal(struct time *p,int n);int main(void){ int n;
#include <stdio.h>
struct time{
int hour, minute, second;
};
void timecal(struct time *p, int n)
{
\x09p->second += n;
\x09if (p->second>=60)
\x09{
\x09\x09p->minute += p->second/60;//60s一分钟
\x09\x09p->second %= 60;//余数为当前秒数\x09\x09
\x09}
\x09if(p->minute>=60)
\x09{
\x09\x09p->hour += p->minute/60;//60分一小时
\x09\x09p->minute %=60;//余数为当前分钟数
\x09}
\x09if (p->hour>=24)
\x09{
\x09\x09p->hour %= 24;//余数为当前小时
\x09}
}
int main(void)
{
int n;
int repeat, ri;
struct time time;
scanf("%d", &repeat);
for(ri = 1; ri <= repeat; ri++){
scanf("%d%d%d", &time.hour, &time.minute, &time.second);
scanf("%d",&n);
timecal(&time,n);
printf("time: %d:%d:%d\n", time.hour, time.minute, time.second);
\x09}
\x09\x09
\x09return 0;
}
//测试无误