In this article, we are going to learn how to convert a number of days into years, weeks, and days format. User can enter the number of days count and we will convert it to years, weeks, and days format. Once the user will enter the number of days we will divide it by 365 to find the number of years. Then the remainder number of days, we will use to calculate weeks and days. Taking one week as 7 days we will divide the remaining days by 7. This will give us a number of weeks.
C program to convert days in to years, weeks and days
#include <stdio.h>
int main()
{
int days, years, weeks;
int daysleft;
printf("Please enter the number of days: ");
scanf("%d", &days);
years = (days / 365);
weeks = (days % 365) / 7;
daysleft = days - ((years * 365) + (weeks * 7));
printf("The days count of %d is equal to: \n", days);
printf("%d Years , %d Weeks and %d Days\n", years,weeks,daysleft);
return 0;
}
Output
Please enter the number of days: 45
The days count of 45 is equal to:
0 Years , 6 Weeks and 3 Days