C program to convert days to years weeks and days

Sure! Here’s a C program that converts a given number of days into years, weeks, and remaining days

				
					#include <stdio.h>

int main() {
  int days, years, weeks, remainingDays;

  printf("Enter the number of days: ");
  scanf("%d", & days);

  years = days / 365;
  weeks = (days % 365) / 7;
  remainingDays = (days % 365) % 7;

  printf("%d days is equivalent to %d years, %d weeks, and %d days.\n", days, years, weeks, remainingDays);

  return 0;
}
				
			
Output
C Program to Convert Given Number of Days into Years, Weeks, and Days
  • In this program, we declare four integer variables: days to store the input number of days, years to store the calculated number of years, weeks to store the calculated number of weeks, and remainingDays to store the remaining days after calculating the years and weeks.

  • The user is prompted to enter the number of days, which is then stored in the days variable using the scanf function.

  • Next, we perform the calculations to convert the number of days into years, weeks, and remaining days. The years variable is assigned the integer division of days by 365, which gives the number of years. The weeks variable is calculated by taking the modulus of days by 365 to get the remaining days and then dividing it by 7 to get the number of weeks. Finally, the remainingDays variable is calculated by taking the modulus of days by both 365 and 7.

  • Finally, we use printf to display the result, showing the original number of days and the converted equivalent in years, weeks, and days.