Convert specified days into years, weeks and days

C program to convert specified days into years, weeks and days.

Program

#include<stdio.h>
#include<conio.h>
void main()
{
    int n_days, days, years, weeks;

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

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

   	printf("\nYears: %d", years);
   	printf("\nWeeks: %d", weeks);
   	printf("\nDays: %d ", days);

	getch();
}

Output

Enter the number of days        : 4356

Years: 11
Weeks: 48
Days: 5

Explanation

In the above program, number of days is taken as an input and stored in the variable named 'n_days'. Number of years, weeks and days are stored in variables named 'years', 'weeks' and 'days' respectively.

The approach used is as follows:
For the number of years, divide the input by 365(no of days in a year) and obtain its quotient.
years = n_days/365;

Now, obtain the remaining number of days after calculating the number of years. This is done by dividing the input by 365 and obtaining its remainder. This is done using modulo operator.
i.e. n_days % 365

Now, for the number of weeks, divide the remainder obtained above by 7(no of days in a week) and obtain its quotient.
weeks = (n_days % 365)/7;

Similarly, for the number of days, divide the input by 365 and obtain its remainder and then further divide the remainder by 7(no of days in a week) and obtain its remainder. This is done using modulo operator.
days = (n_days % 365) % 7;

Let us understand the above process using an example,

n_days = 4356

years = n_days/365; years = 4356 / 365 = 11
weeks = (n_days % 365)/7; weeks = (4356 % 365) / 7 = 341 / 7 = 48
days = (n_days % 365) % 7; days = (4356 % 365) % 7 = 341 % 7 = 5