URI – BEECROWD – BEE Online Judge || Age In Days – URI – BEE 1020 Solution in C,C++, Python
Beecrowd 1020 Solution in C
#include <stdio.h>
int main() {
int d,y,m;
scanf("%d",&d);
y=0;
m=0;
y=d/365;
d=d%365;
m=d/30;
d=d%30;
printf("%d ano(s)\n%d mes(es)\n%d dia(s)\n",y,m,d);
return 0;
}
Code Explanation in 4 Points
1️⃣ Input & Initialization:
- The program reads an integer
d
(total days) from the user. - It initializes
y = 0
(years) andm = 0
(months).
2️⃣ Year Calculation:
y = d / 365
extracts the number of years.d = d % 365
updatesd
to the remaining days.
3️⃣ Month Calculation:
m = d / 30
extracts the number of months.d = d % 30
updatesd
to the remaining days.
4️⃣ Output the Result:
- The program prints the values of
y
,m
, andd
as:X ano(s) Y mes(es) Z dia(s)
Bee1020 Solution in C++
#include <iostream>
using namespace std;
int main() {
int d, y, m;
cin >> d;
y = 0;
m = 0;
y = d / 365;
d = d % 365;
m = d / 30;
d = d % 30;
cout << y << " ano(s)\n" << m << " mes(es)\n" << d << " dia(s)\n";
return 0;
}
Bee1020 Solution in Python
d = int(input())
y = 0
m = 0
y = d // 365
d = d % 365
m = d // 30
d = d % 30
print(f"{y} ano(s)\n{m} mes(es)\n{d} dia(s)")
0 thoughts on “Beecrowd 1020 Solution in C, C++ & Python”