Home > Backend Development > C++ > body text

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
Release: 2023-09-07 18:01:01
forward
1349 people have browsed it

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);
}
Copy after login

Output

Area : 73.2422
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!