Programming Example
C program to convert days to years weeks and days
Study this program carefully to understand the logic, output, and explanation in a structured way.
/**
* 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;
}
Enter days: 373
YEARS: 1
WEEKS: 1
DAYS: 1
Press any key to continue . . .
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.
After understanding this example, try to rewrite the same program without looking at the code. Then change some values or logic and run it again. This helps improve confidence and keeps learners engaged on the page for longer.