Вы можете добавить функцию для расчета # месяцев
#include<stdio.h>
int cal_months(int *days){
int months_arr[] = {31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365}, i, months = 1;
if(*days < 31){
return 0;
}
for(i = 1; i < 12; i++){
if(*days < months_arr[i]){
*days -= months_arr[i-1];
break;
}else{
months ++;
}
}
return months;
}
int main()
{
int in_days, years, months, days, extra, week;
printf("Enter number of days : ");
scanf("%d", &in_days);
if(in_days>1460){
years = in_days/365;
extra = in_days%365;
months = cal_months(&extra);
//days = extra%30;
printf("%d days is same as %d years + %d months + %d days\n", in_days, years, months, extra);
}else if(in_days<1460 && in_days>=365){
years = in_days/365;
extra = in_days%365;
months = cal_months(&extra);
//days = extra%30;
printf("%d days is same as %d years + %d months + %d days\n", in_days, years, months, extra);
}else if(in_days<365){
days = in_days;
months = cal_months(&days);
printf("%d days is same as %d months + %d days\n", in_days, months, days);
}else if(in_days<31){
week= in_days/7;
days = in_days%7;
printf("%d days is same as %d weeks+ %d days\n", in_days, week, days);
}
return 0;
}
Примечание. Этот код не учитывает год LEAP. Вы должны добавить свою собственную логику, чтобы включить эту функцию.