#include <stdio.h>
int main(void)
{
int days, hours, mins;
float a, b, c, total, temp, tempA, tempB;
a = 3.56;
b = 12.50;
c = 9.23;
total = a+b+c;
days = total/24;
temp = total/24 - days;
hours = temp * 24;
tempA = temp*24 - hours;
mins = tempA*60;
while (hours >= 24)
{
hours= hours-24;
days +=1;
}
while (mins >= 60)
{
mins=mins-60;
hours +=1;
}
printf("days:%d\n", days);
printf("hours:%d\n", hours);
printf("mins:%d\n", mins);
return 0;
}
我想小数小时转化为真正的时间,我可以做到这一点很好,但我想增加天时间,如果时间超过24分钟,如果超过60分钟。 while循环会减去它并打印出新的值,但小时/天不会变得复杂。 这是1天1小时77分 我想它读1天2小时17分 但我1天1小时17分钟。复合/ while循环
您可能需要手动检查你的数学; '3.56 + 12.5 + 9.23 == 25.29',比一天多1.29分钟。 – sarnold 2011-02-28 02:42:03
嗯是啊我认为我做了我的数学错误 – 2011-02-28 02:47:45
为什么你要避免一个mod运算符'%'的任何特定原因?你的实现会变得更加简单。 – bits 2011-02-28 02:57:51