#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 分钟。