scanf("%d %d %d", &totalWeeksWorked, &totalDaysWorked, &totalHoursWorked);
答案 0 :(得分:2)
这不是最快的方法,但可能是最具说明性的方式:
int numodweeks = input/(7*24);
int numofdays =input/24;
int numofhours = 24 - (input/24);
使用modulo:
int numofweeks = input/(7*24);
int numofdays = (input%numofweeks)/7;
int numofhours = (input%(numofdays*24));
然后按照你想要的方式显示它们。
答案 1 :(得分:0)
#include <stdio.h>
int const HOURS_PER_WEEK = 40;
int const HOURS_PER_DAY = 7;
int main() {
int total_hours = 59; // this is the input you get
int remaining = total_hours; // 'remaining' is scratch space
int weeks = remaining / HOURS_PER_WEEK;
remaining %= HOURS_PER_WEEK;
int days = remaining / HOURS_PER_DAY;
remaining %= HOURS_PER_DAY;
int hours = remaining;
printf("%d hours = %d weeks, %d days, %d hours\n",
total_hours, weeks, days, hours);
return 0;
}