In this tutorial, we learn **C Program to Convert Days Into Years, Weeks and Days.**

**1. To calculate year in given days (nodays)**

As we know 1 year has 365 days so dividing total days by 365 gives the answers which are a total year present on given days.

=> nodays / 365

**2. To calculate weeks in given days**

For this, we find modules of given number and 365. Which gives a reminder. This reminder we divide by 7.

=> (nodays % 365) / 7

**3. To calculate days remaining in given days**

For this, we find modules of given number and 365. Which gives a reminder. reminder we again apply modules by 7.

=> (nodays % 365) %7

**Example:**

Let’s us take total days = 500

Calculate years, weeks and days in total days using the above technique.

**1. Years**

=> years = days ÷ 365

=> years = 1

**2. Weeks**

=> weeks = ( days % 365 ) / 7

=> weeks = 500 % 365 => 135 / 7 => 19

**3. Days**

=> days = ( days % 365 ) %7

=> days = 500 % 365 => 135 % 7 => 2

## C Program to Convert Days Into Years, Weeks and Days

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#include<stdio.h> void main() { int nodays,years, weeks,days; printf("Enter the total days\n"); scanf("%d",&nodays); years=nodays/365; weeks=(nodays%365)/7; days=(nodays%365)%7; printf("%d = %d years,%d weeks,%d days\n",nodays,years,weeks,days); } |

**Output:**

**Explanation**:

**1. Write the main function**

**2. Declare variable **

**3. Now calculate year, month and day**

years=nodays/365;

weeks=(nodays%365)/7;

days=(nodays%365)%7;

**4. Print the year, month and day.**

## Leave a Reply