C program to convert days to years weeks and days

Previous
Next

Input

            Enter days: 373

Output

            373 days = 1 year/s, 1 week/s and 1 day/s

Days conversion formula

            1 year = 365 days (Ignoring leap year)

            1 week = 7 days

Using this we can define our new formula to compute years and weeks.

            year = days / 365

            week = (days – (year * 365)) / 7

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

    printf("Enter days: ");
    scanf("%d", &days);

    years = (days / 365); 
    weeks = (days % 365) / 7;
    days  = days - ((years * 365) + (weeks * 7));

    printf("YEARS: %d\n", years);
    printf("WEEKS: %d\n", weeks);
    printf("DAYS: %d", days);
    return 0;
}
Previous
Next

Add Comment

Courses Enquiry Form