Days to Years Months Days in C++
Q. Write a program to convert days into years months and days.
#include <iostream>
using namespace std;
int main(){
int d, years, months, days, t;
cout << "Enter number of days : ";
cin >> d;
years = d / 365;
t = d % 365;
months = t / 30;
days = t % 30;
cout<< years << " years " << months << " months " << days << " days";
return 0;
}
Q. Write a program to convert days into years months and days.
1. Start
2. Prompt the user to enter the total number of days `d`.
3. Read the input value of `d`.
4. Calculate the number of years:
- `years = d / 365`
(Assuming 1 year = 365 days)
5. Calculate the remaining days after extracting years:
- `t = d % 365`
6. Calculate the number of months from the remaining days:
- `months = t / 30`
(Assuming 1 month = 30 days)
7. Calculate the remaining days after extracting months:
- `days = t % 30`
8. Print the results:
- `years` years, `months` months, `days` days
9. End
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.
point.com