C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

Convert days to Years, Weeks, Days Program in C

Introduction

In many real-life applications (like HR systems, leave management, or project tracking), we need to convert a large number of days into years, weeks, and remaining days.

  • We assume:
    • 1 Year = 365 Days (ignoring leap years for simplicity)
    • 1 Week = 7 Days

Formula:

  • years = days / 365
  • weeks = (days % 365) / 7
  • days_left = (days % 365) % 7

 

C Program: Convert days to Years, Weeks, Days

C

#include <stdio.h>

 

int main() {

    int total_days, years, weeks, days_left;

 

    // Input total number of days

    printf("Enter total number of days: ");

    scanf("%d", &total_days);

 

    // Conversion logic

    years = total_days / 365;               // Get years

    weeks = (total_days % 365) / 7;         // Get weeks from remaining days

    days_left = (total_days % 365) % 7;     // Remaining days

 

    // Display result

    printf("\n%d days = %d year(s), %d week(s), and %d day(s)\n",

           total_days, years, weeks, days_left);

 

    return 0;

}

Output

 
OUTPUT :
Enter total number of days: 1329

1329 days = 3 year(s), 33 week(s), and 3 day(s)

Explanation

  1. Input total number of days from user.
  2. Divide by 365 to get number of years.
  3. Use modulo (%) to get remaining days after years.
  4. From those remaining days:
    • Divide by 7 → number of weeks.
    • Modulo 7 → leftover days.
  5. Print the converted result.