C++ Program to calculate area of a Enneagon

In this tutorial, we are going to see how to calculate the area of Enneagon using C++ program. Here, firstly we will learn about Enneagon, how to calculate the area of Enneagon. After that, we will learn how to write a C++ code to calculate the area of the Enneagon.

Enneagon

An Enneagon is a nine-sided polygon. It is also called as Nonagon. In nonagon ‘nona’ means nine and ‘gon’ means sides. Nonagon consists of nine interior as well as nine exterior angles. The sum of the interior angles of a nonagon is 1260°. The sum of all the nine exterior angles of a nonagon is 360°. And its area is equal to (perimeter x apothem)/2. See the example in the diagram:-

Enneagon

Formula for calculation of area of regular Enneagon

In a regular Enneagon each interior angle is 140°. And the area is calculated by the following formula:-

Total area= Area of nine small triangles formed
= (1/2)*b*h*9     where b is the side of nonagon and h is the height of triangles or apothem.
= (1/2)*(9*b)*h   where 9*b=perimeter of nonagon (P).
= (P*h)/2
= (P*a)/2              where h=a=apothem
Apothem: The apothem of a regular polygon is the shortest distance from the center point to one of the sides.

Formula for apothem of a regular polygon is given by:
a=side/2*tan(180/n)                   where n=number of sides of the polygon

For Enneagon, a=side/2*tan(180/9)

Area of Enneagon=(P*a)/2
= (9*side*a)/2
= (9*side*side)/(2*2*tan(180/9))
= side2* 6.181824

C++ program to calculate area of Enneagon

So, here is the code implementation of the code to calculate area of Enneagon:-

#include<bits/stdc++.h>
using namespace std; 

/*==============================================
     FUNCTION TO CALCULATE AREA OF ENNEAGON
===============================================*/
double calculate_area(double side) 
{ 
 	return (side * side * 6.181824); 
} 

/*==============================================
     		MAIN FUNCTION
===============================================*/
int main() 
{ 
  double side = 7; // Length of a side 
  double area= calculate_area(side);
  cout << "Area of the given Enneagon = "<<area; 
  return 0; 
} 

In the above code, we have created a function calculate_area() where we have to take double side as the parameter. Now we are ready to run the code. Let’s see if the output can give the result…

Output:-

Area of the given Enneagon = 302.909

Thanks for reading this tutorial. I hope it helps you !!

Leave a Reply

Your email address will not be published. Required fields are marked *