2012-05-06 10:18:14Morris
[UVA][EASY][Math] 10432 - Polygon Inside A Circle
The Problem
Consider a polygon of equal sides inside a circle as shown in the figure below.
Figure: The regular polygon inside a circle
Given the radius of the circle and number of sides. You have to find the area of the polygon.
The Input
In each line there will be two numbers indicating the radius `r' (0<r<20000) and the number of sides of the polygon `n' (2<n<20000) respectively. Input is terminated by `EOF'.The Output
Output the area in each line. The number must be rounded to the third digit after the decimal point.Sample Input
2 2000 10 3000
Sample Output
12.566 314.159
#include <stdio.h>
#include <math.h>
int main() {
double r, n;
while(scanf("%lf %lf", &r, &n) == 2) {
printf("%.3lf\n", n*r*r*sin(2*acos(-1)/n)/2);
}
return 0;
}