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?

In the C program, translate the following into Chinese: What is the area of ​​the largest circle inscribed in an N-sided regular polygon?

WBOY
WBOYforward
2023-09-07 18:01:011371browse

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"

In the C program, translate the following into Chinese: What is the area of ​​the largest circle inscribed in an N-sided regular polygon?

The method is simple. An N-sided polygon can be divided into N equal triangles, each with a central angle of 360/N, so -

In the C program, translate the following into Chinese: What is the area of ​​the largest circle inscribed in an N-sided regular polygon?

Example

#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);
}

Output

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete