系统会为您提供天数,任务是按照年,周和天数转换给定的天数。
让我们假设一年中的天数= 365
年数=(天数)/ 365
说明-:年数将是给定天数除以365所得的商
周数=(天数%365)/ 7
说明-:将通过将天数除以365,再将结果除以一周中的天数,即7,就可以得到星期数。
天数=(天数%365)%7
说明-:天数将通过将天数除以365收集余数,再将部分余数除以一周中的天数得到,从而获得余数。
Input-:days = 209 Output-: years = 0 weeks = 29 days = 6 Input-: days = 1000 Output-: years = 2 weeks = 38 days = 4
Start Step 1-> declare macro for number of days as const int n=7 Step 2-> Declare function to convert number of days in terms of Years, Weeks and Days void find(int total_days) declare variables as int year, weeks, days Set year = total_days / 365 Set weeks = (total_days % 365) / n Set days = (total_days % 365) % n Print year, weeks and days Step 3-> in main() Declare int Total_days = 209 Call find(Total_days) Stop
#include <stdio.h>
const int n=7 ;
//查找年,周,日
void find(int total_days) {
int year, weeks, days;
//假设不是not年
year = total_days / 365;
weeks = (total_days % 365) / n;
days = (total_days % 365) % n;
printf("years = %d",year);
printf("\nweeks = %d", weeks);
printf("\ndays = %d ",days);
}
int main() {
int Total_days = 209;
find(Total_days);
return 0;
}输出结果
如果我们运行以上代码,它将在输出后产生
years = 0 weeks = 29 days = 6