Home / Programs / C program to convert days to years weeks and days
Programming Example

C program to convert days to years weeks and days

👁 2,781 Views
💻 Practical Program
📘 Step by Step Learning
Study this program carefully to understand the logic, output, and explanation in a structured way.

Program Code

/**
 * C program to convert days in to years, weeks and days
 */
 
#include"stdio.h"
 
int main()
{
    int days, years, weeks;
 
    // Read total number of days from user
    printf("Enter days: ");
    scanf("%d", &days);
 
    years = (days / 365);   //Ignoring leap year
    weeks = (days % 365) / 7;
    days  = days - ((years * 365) + (weeks * 7));
 
    printf("YEARS: %d\n", years);
    printf("WEEKS: %d\n", weeks);
    printf("DAYS: %d \n", days);
 
    return 0;
} 

Output

Enter days: 373
YEARS: 1
WEEKS: 1
DAYS: 1
Press any key to continue . . .

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.