标签:logs stdio.h 运行 有用 scan round 错误 second cpp
//四舍五入的程序实现是:math.h里的round函数;此题中是秒的四舍五入,怎么写呢?
//从所得的秒,转化成对应的小时,分(这种转换的思路应该很清晰)
//两位的输出格式?高位不足用0补
#include<stdio.h>
int main()
{
int c1,c2;
scanf("%d%d",&c1,&c2);
int sec;
sec=c2-c1;
//四舍五入的实现,思考为啥模100,为啥跟50比较?
if(sec%100>=50)//此处没有用const int CLK啥的,直接写100的;别忘了写等号,否则有错误
sec=sec/100+1;
else
sec=sec/100;
int hour;
int minute;
int second;
hour=sec/3600;
minute=sec%3600/60;
second=sec%3600%60;//求模运算(求余数)其实有两步:第一步算整除,然后减掉这个整除的,剩下的为余数
printf("%02d:%02d:%02d\n",hour,minute,second);
return 0;
}
标签:logs stdio.h 运行 有用 scan round 错误 second cpp
原文地址:http://www.cnblogs.com/dusanlang/p/7287060.html