A polygon surface area calculation problem.
The formula for the regular n-gon’s area is:
And since the interior angle of a polygon is ,
C++ implementation:
#include <iostream> #include <cmath> using namespace std; typedef long double gtype; const gtype pi = M_PI; #define polA(n) (((n) - 2) * pi / (n)) int main() { gtype r, n; cout.precision(3); while(cin >> r >> n) cout << fixed << (r * r * sin(polA(n)) * n * 0.5) << endl; return 0; }