C Program to Convert Days into Years Weeks and Days
C program to convert days into years weeks and days.
In this article, you will learn how to make a c program to convert days into years weeks, and days.
Example
Enter the days::
464
1 Year, 14 Weeks, and 85 Days
You should have knowledge of the following topics in c programming to understand this program:
- C
main()
function - C
printf()
function
Base Knowledge
1Year = 365days
1Week = 7days
Standard formula to calculate the year, weeks, and days
y = (d / 365)
w = (d % 365) / 7
d = d - ((y * 365) + (w))
Where
y = year
w = week
d = day
Source Code
// C Program to Convert Days into Years Weeks and Days
#include <stdio.h>
int main() {
int d, y, w;
// d = days
// y = years
// w = weeks
printf("Enter the days::\n");
scanf("%d", &d);
// It will make conversion of days in to years, weeks and days
y = (d / 365);
w = (d % 365) / 7;
d = d - ((y * 365) + (w));
// It will produce the final output
printf("\n%d Year, %d Weeks, and %d Days\n", y, w, d);
return 0;
}
Output
Enter the days::
464
1 Year, 14 Weeks, and 85 Days
Explanation
In this above program, we have taken an input 464
number of total days then used the standard formula to calculate the number of years, number of weeks, and number of days then It returned the following values:
- 1 Year
- 14 Weeks
- 85 Days
Also, visit these links
C Program to Enter Marks of Five Subjects and Calculate Percentage and Grade
C++ Program to Calculate Percentage and Grade
Java Program to Calculate Grades of students
Python Program to Calculate Total Marks Percentage and Grade of a Student