C Programming Code Examples C > Conversions Code Examples Convert a Given Number of Days in terms of Years, Weeks & Days Convert a Given Number of Days in terms of Years, Weeks & Days This program takes the number of days as input and converts in terms of years, weeks & days. 1. Take the number of days as input. 2. For the number of years, divide the input by 365 and obtain its quotient. 3. For the number of weeks, divide the input by 365 and obtain its remainder. Further divide the remainder by 7(no of days in a week) and obtain its quotient. 4. For the number of days, divide the input by 365 and obtain its remainder. Further divide the remainder by 7(no of days in a week) and obtain its remainder. /* - C program to convert given number of days to a measure of time given - in years, weeks and days. For example 375 days is equal to 1 year - 1 week and 3 days (ignore leap year) */ #include <stdio.h> #define days-in-week 7 void main() { int ndays, year, week, days; printf("Enter the number of days\n"); scanf("%d", &ndays); year = ndays / 365; week =(ndays % 365) / days-in-week; days =(ndays % 365) % days-in-week; printf ("%d is equivalent to %d years, %d weeks and %d daysn", ndays, year, week, days); } Program Explanation - Take the number of days as input and store it in variable ndays. - For the number of years, divide the input by 365(no of days in a year) and obtain its quotient. Store this in the variable year. - For the number of weeks, divide the input by 365 and obtain its remainder. Further divide the remainder by 7(no of days in a week) and obtain its quotient. Store this in the variable week. - For the number of days, divide the input by 365 and obtain its remainder. Further divide the remainder by 7(no of days in a week) and obtain its remainder. Store this in the variable days. - Print the output and exit.