C Program to Convert Days into Years, Weeks and Days: The total days will be represented in years, week and day format.

1. To calculate year in given days
Year = no of days / 365

2. To calculate weeks in given days
Weeks = (no of days % 365) / 7

3. To calculate days remaining in given days
days = (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

Algorithm to convert days into years, weeks and days

  1. Take input total days
  2. Calculate year, month and day by formula
    years=nodays/365;
    weeks=(nodays%365)/7;
    days=(nodays%365)%7;
  3. Print the year, month and day.

C Program to Convert Days into Years, Weeks and Days

#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:

C Program to Convert Days into Years, Weeks and Days

Write A Comment