Computer >> Computer tutorials >  >> Programming >> C programming

C Program for area of decagon inscribed within the circle?


Here we will see how to get the area of decagon which is present inside the circle. The radius is given. The side of the decagon is ‘a’.

C Program for area of decagon inscribed within the circle?

As we know that the side of the decagon is like below −

C Program for area of decagon inscribed within the circle?

So the area is −

C Program for area of decagon inscribed within the 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