C语言实现时间加秒计算
#include <stdio.h>
int main() { int h, m, s, n, t;
//读入时间
scanf("%d:%d:%d", &h, &m, &s);
//读入秒数
scanf("%d", &n);
//计算时间差
t = h * 3600 + m * 60 + s + n;
//取模,计算新的时间
h = t / 3600 % 24;
m = t % 3600 / 60;
s = t % 60;
//输出结果
printf("%02d:%02d:%02d", h, m, s);
return 0;
}
原文地址: https://www.cveoy.top/t/topic/mGB1 著作权归作者所有。请勿转载和采集!