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 Learning
Learn this program step-by-step with algorithm, source code, output and detailed explanation.

💻 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;
} 
                        

🖥 Program Output

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

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.