B - π Editorial by en_translator
If you are new to learning programming and do not know where to start, please try Problem A “Welcome to AtCoder” from practice contest. There you can find a sample code for each language.
Also, if you are not familiar with problems in programming contests, we recommend you to try some problems in “AtCoder Beginners Selection” (https://atcoder.jp/contests/abs).
The area of a circle can be represented as \(\pi r^2\), using the radius \(r\) and the pi \(\pi\).
Since the radius is half the diameter, we have \(\displaystyle r=\frac d2\). Thus, the sought area can be represented as \(\displaystyle \frac{\pi d^2}4\).
All that left is to compute this value and print it. To use pi, we can use for example pi in math library in Python, or M_PI in cmath library in C++.
from math import pi
d = int(input())
print(d * d * pi / 4)
#include <bits/stdc++.h>
using namespace std;
int main() {
int d;
cin >> d;
cout << fixed << setprecision(20) << M_PI * d * d / 4 << endl;
return 0;
}
posted:
last update: