In this problem, we are given two numbers that give the number of sides of a polygon N and the length of each side A. Our task is to create a Program to find the Circumcircle of any regular polygon in C++.
Problem description − Here, we need to find the radius and area of the circumcircle of the regular polygon whose side number and length are given.
Let’s take an example to understand the problem,
Input
n = 4 a = 2
Solution Approach
To solve the problem, we will first find the radius of the circumcircle of the given polygon.
The formula for the radius of a polygon of side A and N no. of sides is
$r=\square\sqrt{2(1-\square\square\square(360/\square))}$
And using this radius, we will find the area by the formula,
$area =\prod\square^2$
Program to illustrate the working of our solution,
Example
#include <bits/stdc++.h>
using namespace std;
void CalcRadAreaCircumcircle(float n, float a) {
float r = a / sqrt( 2 * ( 1 - cos(360 / n)));
cout<<"The radius of Circumcircle is "<<r<<endl;
cout<<"The area of circumcircle is "<<((3.14)*r*r);
}
int main() {
float n = 5, a = 6;
CalcRadAreaCircumcircle(n, a);
return 0;
}Output
The radius of Circumcircle is 3.02487 The area of circumcircle is 28.7305