/**
* 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 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.
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.