Home >Backend Development >C++ >In the C program, translate the following into Chinese: What is the area of the largest circle inscribed in an N-sided regular polygon?
Here, we will see how to obtain the area of a circle inscribed in an N-sided regular polygon. Given N (the number of sides), each side of the polygon is "a"
The method is simple. An N-sided polygon can be divided into N equal triangles, each with a central angle of 360/N, so -
#include <iostream> #include <cmath> using namespace std; float area(float n, float a) { if (n < 0 || a < 0 ) //if the valuse are negative it is invalid return -1; float r = a/(2.0*tan((180/n) * 3.14159/180)); float area = 3.14159 * r*r; return area; } int main() { float n = 8, a = 4; cout << "Area : " << area(n, a); }
Area : 73.2422
The above is the detailed content of In the C program, translate the following into Chinese: What is the area of the largest circle inscribed in an N-sided regular polygon?. For more information, please follow other related articles on the PHP Chinese website!