In this tutorial learn how you can write a c program to convert no of days into years, months and days. There are 365 days in 1 year and 30 days in 1 month.

For a year we first divide days by 365 and for a month first, we take the remainder of years then divide the remainder by 30.  And for days we take the remainder of years then divide the remainder by 30 and again take the remainder as days. By this, we get years and months and days.

C programming is a powerful general-purpose programming language. It can be used to develop software like operating systems, databases, compilers, etc.

Write a Program to Convert Number of Days into Years, Months and Days

Here is the code to convert number of days into years, months and days.

#include <stdio.h> //WAP to convert no of days into years, months and days.
int main() {
    int days,years,months,day;
    printf("Enter the number of days: ");
    scanf("%d",&days);
    years = days/365;
    months= days%365 / 30;
    day=days%365%30;
    printf("%d Days equals to %d years, %d months, %d days.",days,years,months,day);

return 0;
}

Test Live At Jdoodle

Conclusion

This is how you can convert no of days into years, months and days in c programming. Comment below if you like our tutorial.