C program to convert given number of days into years, weeks and days

In this C program you will know how to convert given number of days into years, weeks and days.

For example:

If user enter 1234 days then.
Years = 3
Weeks = 21
Days = 1
 
Comment below if you are facing any problem to understand the logic of this program.
#include<stdio.h>

int main()
{
	int y,w,d,a;
	printf("Enter total number of days:");
	scanf("%d",&d);

	y=d/365;
	a=d%365;
	w=a/7;
	d=a%7;
	printf("\nYears=%d\nWeeks=%d\nDays=%d",y,w,d);
	
	return 0;
}

 

Output
C program to convert given number of days into years,weeks and days

 

7 thoughts on “C program to convert given number of days into years, weeks and days”

  1. Ruturaj Pansare

    Dear Sir,Your program is completely inappropriate.When we enter days=1234,years should be 3,weeks should be 176[logic =176*7=1232] instead it is showing 21.Simply illogical.
    I recommend a simple program to find no of weeks
    i.e days/7;

      1. logic is absolutely fine but the output in your example may be wrong.
        I think
        Enter a number
        1234
        years = 3
        weeks = 19
        days = 6
        Process returned 0 (0x0) execution time : 2.131 s

Leave a Comment

Your email address will not be published. Required fields are marked *