# C Program to Convert Number of Days to Week, Months and Years

C program to convert Number of Days to Days, Weeks, Months and Years.

#### Required Knowledge

We will first take number of days as input from user using scanf function then convert to Days, Weeks, Months and Years using following conversion equations.

• 1 Year = 365 Days
• 1 Month = 30 Days
• 1 Week = 7 Days

## C program to convert number of days to days, weeks, months and years

```#include <stdio.h>

int main() {
int inputDays, years, months, weeks, days;

/*
* Take number of days as input from user
*/
printf("Enter number of Days\n");
scanf("%d", &inputDays);

/*
* 1 Year = 365 Days, 1 Month = 30 Days, 1 Week = 7 Days
* To keep things simple, We are not considering Leap years
* and assuming 1 Month = 30 Days
*/
years = inputDays/365;
// Remaining days after year
inputDays = inputDays - years*365;
months = inputDays/30;
// Remaining days after month
inputDays = inputDays - months*30;
weeks = inputDays/7;
// Remaining days after week
inputDays = inputDays - weeks*7;
days = inputDays;

printf("Years : %d\n", years);
printf("Months : %d\n", months);
printf("Weeks : %d\n", weeks);
printf("Days : %d", days);

return 0;
}
```

Output
```Enter number of Days
400
Years : 1
Months : 1
Weeks : 0
Days : 5
```

Related Topics
 C Program to generate geometric progression(GP) series C Program to generate harmonic progression(HP) series C program to find all roots of quadratic equation C program to convert decimal numbers to binary numbers C program to multiply two numbers without using arithmetic operators C program to convert temperature from celsius to fahrenheit C program to convert binary number to decimal number system C program to convert octal number to binary number system C program to make a simple calculator using switch statement List of all C programs