Beecrowd 1020 Solution in C, C++ & Python

URI – BEECROWD – BEE Online Judge || Age In Days – URI – BEE 1020 Solution in C,C++, Python

Question

#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) and m = 0 (months).

2️⃣ Year Calculation:

  • y = d / 365 extracts the number of years.
  • d = d % 365 updates d to the remaining days.

3️⃣ Month Calculation:

  • m = d / 30 extracts the number of months.
  • d = d % 30 updates d to the remaining days.

4️⃣ Output the Result:

  • The program prints the values of y, m, and d 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)")

Beecrowd 1019 solution || URI – BEECROWD – BEE 1019 Time Conversion Solutions in C, C++, and Python

0 thoughts on “Beecrowd 1020 Solution in C, C++ & Python”

  1. Pingback: URL

Leave a Comment