# Program to find Area of Triangle inscribed in N-sided Regular Polygon

Given the triangle inscribed in an N-sided regular polygon with given side length, formed using any 3 vertices of the polygon, the task is to find the area of this triangle.

**Examples:**

Input:N = 6, side = 10Output:129.904Input:N = 8, side = 5Output:45.2665

**Approach:** Consider the 1st example:

**(A*P)/2**where P is the perimeter of that polygon and A is apothem of that polygon.

**(A/N)*3**.

Below is the implementation of the above approach:

## C++

`// C++ Program to find the area of a triangle ` `// inscribed in N-sided regular polygon ` ` ` `#include <bits/stdc++.h> ` `#include <cmath> ` `using` `namespace` `std; ` ` ` `// Function to find the area of the polygon ` `double` `area_of_regular_polygon(` `double` `n, ` `double` `len) ` `{ ` ` ` ` ` `// area of a regular polygon with N sides ` ` ` `// and side length len ` ` ` `double` `P = (len * n); ` ` ` `double` `A ` ` ` `= len ` ` ` `/ (2 * ` `tan` `((180 / n) ` ` ` `* 3.14159 / 180)); ` ` ` `double` `area = (P * A) / 2; ` ` ` ` ` `return` `area; ` `} ` ` ` `// Function to find the area of a triangle ` `double` `area_of_triangle_inscribed(` `double` `n, ` `double` `len) ` `{ ` ` ` ` ` `double` `area = area_of_regular_polygon(n, len); ` ` ` ` ` `// area of one triangle ` ` ` `// in an N-sided regular polygon ` ` ` `double` `triangle = area / n; ` ` ` ` ` `// area of inscribed triangle ` ` ` `double` `ins_tri = (triangle * 3); ` ` ` ` ` `return` `ins_tri; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `double` `n = 6, len = 10; ` ` ` ` ` `cout << area_of_triangle_inscribed(n, len) ` ` ` `<< endl; ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java Program to find the area of a triangle ` `// inscribed in N-sided regular polygon ` `import` `java.util.*; ` ` ` `class` `GFG ` `{ ` ` ` `// Function to find the area of the polygon ` `static` `double` `area_of_regular_polygon(` `double` `n, ` ` ` `double` `len) ` `{ ` ` ` ` ` `// area of a regular polygon with N sides ` ` ` `// and side length len ` ` ` `double` `P = (len * n); ` ` ` `double` `A = len / (` `2` `* Math.tan((` `180` `/ n) * ` ` ` `3.14159` `/ ` `180` `)); ` ` ` `double` `area = (P * A) / ` `2` `; ` ` ` ` ` `return` `area; ` `} ` ` ` `// Function to find the area of a triangle ` `static` `double` `area_of_triangle_inscribed(` `double` `n, ` ` ` `double` `len) ` `{ ` ` ` `double` `area = area_of_regular_polygon(n, len); ` ` ` ` ` `// area of one triangle ` ` ` `// in an N-sided regular polygon ` ` ` `double` `triangle = area / n; ` ` ` ` ` `// area of inscribed triangle ` ` ` `double` `ins_tri = (triangle * ` `3` `); ` ` ` ` ` `return` `ins_tri; ` `} ` ` ` `// Driver code ` `static` `public` `void` `main(String[] arg) ` `{ ` ` ` `double` `n = ` `6` `, len = ` `10` `; ` ` ` ` ` `System.out.printf(` `"%.3f"` `, ` ` ` `area_of_triangle_inscribed(n, len)); ` `} ` `} ` ` ` `// This code is contributed by PrinciRaj1992 ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 Program to find the area ` `# of a triangle inscribed in ` `# N-sided regular polygon ` `import` `math ` ` ` `# Function to find the area of the polygon ` `def` `area_of_regular_polygon(n, ` `len` `): ` ` ` ` ` `# area of a regular polygon with ` ` ` `# N sides and side length len ` ` ` `P ` `=` `(` `len` `*` `n); ` ` ` `A ` `=` `len` `/` `(` `2` `*` `math.tan((` `180` `/` `n) ` `*` ` ` `3.14159` `/` `180` `)) ` ` ` `area ` `=` `(P ` `*` `A) ` `/` `2` ` ` ` ` `return` `area ` ` ` `# Function to find the area of a triangle ` `def` `area_of_triangle_inscribed(n, ` `len` `): ` ` ` ` ` `area ` `=` `area_of_regular_polygon(n, ` `len` `) ` ` ` ` ` `# area of one triangle ` ` ` `# in an N-sided regular polygon ` ` ` `triangle ` `=` `area ` `/` `n ` ` ` ` ` `# area of inscribed triangle ` ` ` `ins_tri ` `=` `(triangle ` `*` `3` `); ` ` ` ` ` `return` `ins_tri ` ` ` `# Driver code ` `n ` `=` `6` `len` `=` `10` `print` `(` `round` `(area_of_triangle_inscribed(n, ` `len` `), ` `3` `)) ` ` ` `# This code is contributed by divyamohan ` |

*chevron_right*

*filter_none*

## C#

`// C# Program to find the area of a triangle ` `// inscribed in N-sided regular polygon ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `// Function to find the area of the polygon ` `static` `double` `area_of_regular_polygon(` `double` `n, ` ` ` `double` `len) ` `{ ` ` ` ` ` `// area of a regular polygon with N sides ` ` ` `// and side length len ` ` ` `double` `P = (len * n); ` ` ` `double` `A = len / (2 * Math.Tan((180 / n) * ` ` ` `3.14159 / 180)); ` ` ` `double` `area = (P * A) / 2; ` ` ` ` ` `return` `area; ` `} ` ` ` `// Function to find the area of a triangle ` `static` `double` `area_of_triangle_inscribed(` `double` `n, ` ` ` `double` `len) ` `{ ` ` ` `double` `area = area_of_regular_polygon(n, len); ` ` ` ` ` `// area of one triangle ` ` ` `// in an N-sided regular polygon ` ` ` `double` `triangle = area / n; ` ` ` ` ` `// area of inscribed triangle ` ` ` `double` `ins_tri = (triangle * 3); ` ` ` ` ` `return` `ins_tri; ` `} ` ` ` `// Driver code ` `static` `public` `void` `Main(String[] arg) ` `{ ` ` ` `double` `n = 6, len = 10; ` ` ` ` ` `Console.Write(` `"{0:F3}"` `, ` ` ` `area_of_triangle_inscribed(n, len)); ` `} ` `} ` ` ` `// This code is contributed by PrinciRaj1992 ` |

*chevron_right*

*filter_none*

**Output:**

129.904

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: **DSA Self Paced**. Become industry ready at a student-friendly price.

## Recommended Posts:

- Area of a square inscribed in a circle which is inscribed in an equilateral triangle
- Program to find the Perimeter of a Regular Polygon
- Program to find the Circumcircle of any regular polygon
- Area of a triangle inscribed in a rectangle which is inscribed in an ellipse
- Area of a n-sided regular polygon with given Radius
- Area of a n-sided regular polygon with given side length
- Area of a circle inscribed in a regular hexagon
- Area of largest Circle inscribe in N-sided Regular polygon
- Area of circle which is inscribed in equilateral triangle
- Area of largest triangle that can be inscribed within a rectangle
- Area of the Largest Triangle inscribed in a Hexagon
- Program to find area of a triangle
- Area of Equilateral triangle inscribed in a Circle of radius R
- Maximum area of rectangle inscribed in an equilateral triangle
- Biggest Reuleaux Triangle inscribed within a Square inscribed in an equilateral triangle
- Find the angle of Rotational Symmetry of an N-sided regular polygon
- Biggest Reuleaux Triangle inscribed within a square which is inscribed within an ellipse
- Biggest Reuleaux Triangle inscribed within a square which is inscribed within a hexagon
- Largest square that can be inscribed within a hexagon which is inscribed within an equilateral triangle
- Find the area of largest circle inscribed in ellipse

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.