C Program to Convert Days to Years Weeks and Days

How to write a C Program to Convert Days to Years Weeks, and Days with an example.

C Program to Convert Days to Years Weeks and Days

This program allows the user to enter the number of days, and then convert those days into Years, Weeks and Days. For example, 365 days = 1 year, o Week, and 0 days

 #include <stdio.h>
 
int main()
{
  	int NoOfDays, years, weeks, days;
 
 	printf("\n Please Enter the Number of days  :  ");
  	scanf("%d", &NoOfDays);
  
  	years = NoOfDays / 365;
  	weeks = (NoOfDays % 365) / 7;
  	days = (NoOfDays % 365) % 7;
  	
 
    printf("\n Years  = %d", years);
    printf("\n Weeks  = %d", weeks);
    printf("\n Days   = %d", days);
  
   	return 0;
}
C Program to Convert Days to Years Weeks and Days 1

This program to change Days to Years, Weeks, and Days is the same as the above Programming example. However, this time we defined a Days_in_Week variable and assigned a value 7.

#include <stdio.h>
#define Days_In_Week 7
 
int main()
{
  	int NoOfDays, years, weeks, days;
 
 	printf("\n Please Enter the Number of days  :  ");
  	scanf("%d", &NoOfDays);
  
  	years = NoOfDays / 365;
  	weeks = (NoOfDays % 365) / Days_In_Week;
  	days = (NoOfDays % 365) % Days_In_Week;
  	
 
    printf("\n Years  = %d", years);
    printf("\n Weeks  = %d", weeks);
    printf("\n Days   = %d", days);
  
   	return 0;
}
 Please Enter the Number of days  :  1365

 Years  = 3
 Weeks  = 38
 Days   = 4