Home  >  Article  >  Backend Development  >  C program to find the area of ​​a decagon inscribed in a circle?

C program to find the area of ​​a decagon inscribed in a circle?

WBOY
WBOYforward
2023-09-15 17:21:011069browse

Here we will learn how to get the area of ​​a decagon inside a circle. The radius is given. The side of the decagon is "a".

C program to find the area of ​​a decagon inscribed in a circle?

As we all know, the side lengths of a decagon are as follows-

C program to find the area of ​​a decagon inscribed in a circle?

Example

#include <iostream>
#include <cmath>
using namespace std;
float area(float r) {
   if (r < 0) //if r is negative it is invalid
      return -1;
   float area = (5 * pow(r, 2) * (3 - sqrt(5)) * (sqrt(5) + (2 * sqrt(5)))) / 4;
   return area;
}
int main() {
   float r = 8;
   cout << "Area : " << area(r);
}

Output

Area : 409.969

The above is the detailed content of C program to find the area of ​​a decagon inscribed in a circle?. 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