- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Apothem of a n-sided regular polygon in C++

**n-sided regular polygon** is a closed figure of n sides that has all sides and angles of equal length. The below figure shows a 6 sided regular polygon commonly known as hexagon.

**Apothem** is a line in the polygon that connects the center of the figure to the side. And it is perpendicular to one of its sides that makes it smallest in length.

Now, let drive the formula for its length.

The angle made by the side of an n sided polygon is **360/n**.

Now, as in the figure, the angle is equal to (360 / n )/2 = 180 /n

Now taking the triangle, we can conclude that

tan ø = b/2 / h = b/2h 2h * tan ø = b h = b/2*tanø , ø = 180 /n h = b/2*tan(180/n)

Let's implement this to a program to find the length of apothem when the number of sides and length of each side of the polygon are given.

## Formula

Given n = number of side , b = length of each side. h = length of apothem, h = b/2 * tan(180/n)

## Example

#include<iostream> #include <math.h> using namespace std; void apothemLength(int n, float a){ if (a < 0 && n < 0) cout<<"invalid values"; else cout<<"the length of apothem = "<< (a/(2*tan((180/n)*3.14159/180))); } int main(){ float a = 12; int n = 9; apothemLength(n, a); return 0; }

## Output

the length of apothem = 16.4849

- Related Articles
- Area of a n-sided regular polygon with given Radius?
- Area of a n-sided regular polygon with given side length in C++
- Area of a n-sided regular polygon with given Radius in C Program?
- Area of largest Circle inscribe in N-sided Regular polygon in C Program?
- Area of largest Circle inscribed in N-sided Regular polygon in C Program?
- Determine the position of the third person on regular N sided polygon in C++?
- Determine the position of the third person on regular N sided polygon in C++ Program
- Find number of diagonals in n sided convex polygon in C++
- Probability that the pieces of a broken stick form a n sided polygon in C++
- What is regular polygon ?
- What is a regular polygon?State the name of a regular polygon of(i) 3 sides(ii) 4 sides(iii) 6 sides.
- The interior angle of a regular polygon is $156$ . Find the number of sides of the polygon.
- Each interior angle of a regular polygon is four times the exterior angle. Find the number of sides in the polygon.
- Program to find the Circumcircle of any regular polygon in C++
- What's the minimum exterior angle possible of a regular polygon?

Advertisements