C++ program to find the Area of the Largest Triangle inscribed in a Hexagon?

Find the area of largest Triangle inscribed in a hexagon we need to learn these figures are and how 1 is inscribed inside other.

Triangle is a closed figure with 3 sides which may be equal or different size.

Hexagon is a closed figure with 6 sides which may be equal or unequal in size.

A triangle inscribed inside a hexagon has all its vertices touching vertices of hexagon. So, the sides of the triangle can be treated as diagonals of a regular hexagon. The hexagon considered here is a regular hexagon, which leads to make the largest triangle an Equilateral triangle.

Let’s derive the formula for this,

Please refer to the following image −

In triangle AGB, we apply pythagoras theorem.

(a/2)2 + (s/2)2 = a2 ,a = side of regular hexagon

                     s = side of equilateral triangle

a2/4 + s2/4 = a2

a2 - a2/4 = s2/4 3a2/4 = s2/4 3a2 = s2 a√3 = s Area = (3√3*a^2)/4

Let’s take an example,

Side of hexagon = 6

Area of triangle = 46.7654

Explanation, Area = 3√3*36/4 = 46.7654


 Live Demo

#include <iostream>
#include <math.h>
using namespace std;
int main() {
   float a = 6;
   if (a < 0)
      cout<<"Wrong Input!";
   float area = (3 * sqrt(3) * pow(a, 2)) / 4;
   cout <<"The area of the triangle is "<<area;
   return 0;


The area of the triangle is 46.7654