C PROGRAMMING PROGRAM • BASICS & INPUT/OUTPUT
Convert Days into Years, Weeks and Days
Learn how to convert days into years, weeks and days using a clear C program.
PROBLEM UNDERSTANDING
Input and expected output
Sample input
800
Sample output
2 year(s), 10 week(s), 0 day(s)
COMPLETE C PROGRAM
Complete C implementation
#include <stdio.h>
int main(void)
{
int totalDays, years, weeks, days;
printf("Enter total days: ");
scanf("%d", &totalDays);
years = totalDays / 365;
totalDays %= 365;
weeks = totalDays / 7;
days = totalDays % 7;
printf("%d year(s), %d week(s), %d day(s)\n", years, weeks, days);
return 0;
}CURRENT STEP
SELECTED LINE
EXPECTED OUTPUT FOR THE SAMPLE
2 year(s), 10 week(s), 0 day(s)
Step 0 of 0
PROGRAM EXPLANATION
Algorithm and explanation
- Read the required input values.
- Repeatedly use integer division and remainder from the largest unit to the smallest.
- Display the computed result.
Repeatedly use integer division and remainder from the largest unit to the smallest.
EFFICIENCY
Time and space complexity
Time complexity
O(1)
Auxiliary space
O(1)
DEBUGGING CHECKLIST
Common mistakes
Check this
Use the correct format specifier for every variable.
Check this
Initialize variables before using their values.
Check this
Check braces, semicolons and input order carefully.
Try it yourself
Practice: Run the program with the sample input, predict its output, and then test one boundary case of your own.
