# Largest hexagon that can be inscribed within an equilateral triangle

Given an equilateral triangle of side length **a**, the task is to find the largest hexagon that can be inscribed within it.

**Examples:**

Input:a = 6

Output:2

Input:a = 9

Output:3

**Approach:** From the figure, it is clear that the three small triangles are also equilateral. So they will have side length **b = a / 3** where **b** is also the length of the hexagon and **a** is the length of the given equilateral triangle.

Below is the implementation of the above approach:

## C++

`// C++ program to find the side of the ` `// largest hexagon which can be inscribed ` `// within an equilateral triangle ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to find the side ` `// of the hexagon ` `float` `hexagonside(` `float` `a) ` `{ ` ` ` ` ` `// Side cannot be negative ` ` ` `if` `(a < 0) ` ` ` `return` `-1; ` ` ` ` ` `// Side of the hexagon ` ` ` `float` `x = a / 3; ` ` ` `return` `x; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `float` `a = 6; ` ` ` `cout << hexagonside(a) << endl; ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to find the side of the ` `// largest hexagon which can be inscribed ` `// within an equilateral triangle ` `class` `CLG ` `{ ` `// Function to find the side ` `// of the hexagon ` ` ` `static` `float` `hexagonside(` `float` `a) ` `{ ` ` ` ` ` `// Side cannot be negative ` ` ` `if` `(a < ` `0` `) ` ` ` `return` `-` `1` `; ` ` ` ` ` `// Side of the hexagon ` ` ` `float` `x = a / ` `3` `; ` ` ` `return` `x; ` `} ` ` ` `// Driver code ` `public` `static` `void` `main(String[] args) ` `{ ` ` ` `float` `a = ` `6` `; ` ` ` `System.out.println(hexagonside(a)); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## Python3

# Python3 program to find the side of the

# largest hexagon which can be inscribed

# within an eqilateral triangle

# function to find the side of the hexagon

def hexagonside(a):

# Side cannot be negative

if a < 0:
return -1
# Side of the hexagon
x = a // 3
return x
# Driver code
a = 6
print(hexagonside(a))
# This code is contributed
# by Mohit kumar 29
[tabby title="C#"]

`using` `System; ` `// C# program to find the side of the ` `// largest hexagon which can be inscribed ` `// within an equilateral triangle ` `class` `CLG ` `{ ` `// Function to find the side ` `// of the hexagon ` ` ` `static` `float` `hexagonside(` `float` `a) ` `{ ` ` ` ` ` `// Side cannot be negative ` ` ` `if` `(a < 0) ` ` ` `return` `-1; ` ` ` ` ` `// Side of the hexagon ` ` ` `float` `x = a / 3; ` ` ` `return` `x; ` `} ` ` ` `// Driver code ` `public` `static` `void` `Main() ` `{ ` ` ` `float` `a = 6; ` ` ` `Console.Write(hexagonside(a)); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program to find the side of the ` `// largest hexagon which can be inscribed ` `// within an equilateral triangle ` ` ` `// Function to find the side ` `// of the hexagon ` `function` `hexagonside(` `$a` `) ` `{ ` ` ` ` ` `// Side cannot be negative ` ` ` `if` `(` `$a` `< 0) ` ` ` `return` `-1; ` ` ` ` ` `// Side of the hexagon ` ` ` `$x` `= ` `$a` `/ 3; ` ` ` `return` `$x` `; ` `} ` ` ` `// Driver code ` `$a` `= 6; ` `echo` `hexagonside(` `$a` `) ; ` ` ` `// This code is contributed by Ryuga ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

2

## Recommended Posts:

- Largest square that can be inscribed within a hexagon which is inscribed within an equilateral triangle
- Area of the Largest Triangle inscribed in a Hexagon
- Biggest Reuleaux Triangle inscribed within a Square inscribed in an equilateral triangle
- Area of a square inscribed in a circle which is inscribed in an equilateral triangle
- Biggest Reuleaux Triangle inscribed within a square which is inscribed within a hexagon
- Area of circle which is inscribed in equilateral triangle
- Biggest Square that can be inscribed within an Equilateral triangle
- Count of distinct rectangles inscribed in an equilateral triangle
- Largest Square that can be inscribed within a hexagon
- Largest hexagon that can be inscribed within a square
- Largest triangle that can be inscribed in an ellipse
- Largest triangle that can be inscribed in a semicircle
- Area of largest triangle that can be inscribed within a rectangle
- Area of a square inscribed in a circle which is inscribed in a hexagon
- Biggest Reuleaux Triangle inscribed within a square which is inscribed within an 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.