Home > Backend Development > C++ > 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
Release: 2023-09-15 17:21:01
forward
1085 people have browsed it

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

Output

Area : 409.969
Copy after login

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!

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