-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathR_Age_in_Days.cpp
73 lines (62 loc) · 1.83 KB
/
R_Age_in_Days.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// #include <iostream>
// using namespace std;
// int main()
// {
// long long N;
// int years = 0, months = 0, temp = 0;
// cin >> N;
// if (N >= 365)
// {
// years = N / 365;
// cout << years << " years" << endl;
// temp = N % 365;
// if (temp >= 30)
// {
// months = temp / 30;
// cout << months << " months" << endl;
// temp = temp % 30;
// if (temp >= 0)
// cout << temp << " days" << endl;
// }
// else
// {
// cout<<months<<" months"<<endl;
// cout<<temp<< " days"<< endl;
// }
// }
// else
// {
// if (N >= 30)
// {
// months = N / 30;
// cout << years << " years" << endl;
// cout << months << " months" << endl;
// temp = N % 30;
// if (temp >= 0)
// cout << temp << " days" << endl;
// }
// else
// {
// cout << years << " years" << endl;
// cout << months << " months" << endl;
// cout << N << " days" << endl;
// }
// }
// return 0;
// }
//A more straight forward way to solve this question, without using nested if-else conditions.
#include <iostream>
using namespace std;
int main() {
long long N;
cin >> N;
int years = N / 365; // Calculate total years
N %= 365; // Remaining days after calculating years
int months = N / 30; // Calculate total months from remaining days
int days = N % 30; // Remaining days after calculating months
// Output the results
cout << years << " years" << endl;
cout << months << " months" << endl;
cout << days << " days" << endl;
return 0;
}