https://pintia.cn/problem-sets/994805260223102976/problems/994805295203598336
四舍五入用函数 round()。
#include<iostream>
#include<math.h>
using namespace std;
int main(){
int c1, c2, h=0, m=0, s=0;
double c3;
cin >> c1 >> c2;
c3 = (c2 - c1)/100.0;
while(c3>=60){
c3-=60;
m+=1;
if(m==60){
h++;
m=0;
}
}
s=round(c3);
printf("%02d:%02d:%02d\n", h, m, s);
}
这是一个C++程序,它接受两个整数输入,计算它们之间的差距(以分钟为单位),然后四舍五入到最接近的整秒。程序利用while循环和数学的四舍五入函数round()进行计算,并以HH:MM:SS的格式输出结果。
433

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



