Given here is an equilateral triangle of side length **a**, which inscribes a hexagon which in turn inscribes a square. The task is to find the side length of the square.

**Examples:**

Input:a = 6Output:2.538Input:a = 8Output:3.384

**Approach**:

We know the, side length of a hexagon inscribed within an equilateral triangle is **h = a/3**. Please refer Largest hexagon that can be inscribed within an equilateral triangle .

Also, the side length of the square that can be inscribed within a hexagon is **x = 1.268h** Please refer Largest Square that can be inscribed within a hexagon.

So, side length of the square inscribed within a hexagon which in turn is inscribed within an equilateral triangle, **x = 0.423a**.

Below is the implementation of the above approach:

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

*chevron_right*

*filter_none*

`// Java program to find the side of the ` `// largest square that can be inscribed ` `// within the hexagon which in return is ` `// incsribed within an equilateral triangle ` `class` `cfg `
`{ ` ` ` `// Function to find the side ` `// of the square ` `static` `float` `squareSide(` `float` `a) `
`{ ` ` ` ` ` `// Side cannot be negative `
` ` `if` `(a < ` `0` `) `
` ` `return` `-` `1` `; `
` ` ` ` `// side of the square `
` ` `float` `x = (` `0` `.423f * a); `
` ` `return` `x; `
`} ` ` ` `// Driver code ` `public` `static` `void` `main(String[] args) `
`{ ` ` ` `float` `a = ` `8` `; `
` ` `System.out.println(squareSide(a)); `
` ` `} ` `} ` ` ` `// This code is contributed by ` `// Mukul Singh. ` |

*chevron_right*

*filter_none*

`# Python 3 program to find the side of the ` `# largest square that can be inscribed ` `# within the hexagon which in return ` `# is incsribed within an equilateral triangle ` ` ` `# Function to find the side of the square ` `def` `squareSide(a): `
` ` ` ` `# Side cannot be negative `
` ` `if` `(a < ` `0` `): `
` ` `return` `-` `1`
` ` ` ` `# side of the square `
` ` `x ` `=` `0.423` `*` `a `
` ` `return` `x `
` ` `# Driver code ` `if` `__name__ ` `=` `=` `'__main__'` `: `
` ` `a ` `=` `8`
` ` `print` `(squareSide(a)) `
` ` `# This code is contributed by ` `# Sanjit_Prasad ` |

*chevron_right*

*filter_none*

`// C# program to find the side of the ` `// largest square that can be inscribed ` `// within the hexagon which in return is ` `// incsribed within an equilateral triangle ` `using` `System; `
` ` `class` `GFG `
`{ ` ` ` `// Function to find the side ` `// of the square ` `static` `float` `squareSide(` `float` `a) `
`{ ` ` ` ` ` `// Side cannot be negative `
` ` `if` `(a < 0) `
` ` `return` `-1; `
` ` ` ` `// side of the square `
` ` `float` `x = (0.423f * a); `
` ` `return` `x; `
`} ` ` ` `// Driver code ` `public` `static` `void` `Main() `
`{ ` ` ` `float` `a = 8; `
` ` `Console.WriteLine(squareSide(a)); `
`} ` `} ` ` ` `// This code is contributed by ` `// shs ` |

*chevron_right*

*filter_none*

`<?php ` `// PHP program to find the side of the ` `// largest square that can be inscribed ` `// within the hexagon which in return is ` `// incsribed within an equilateral triangle ` ` ` `// Function to find the side of the square ` `function` `squareSide(` `$a` `) `
`{ ` ` ` ` ` `// Side cannot be negative `
` ` `if` `(` `$a` `< 0) `
` ` `return` `-1; `
` ` ` ` `// side of the square `
` ` `$x` `= 0.423 * ` `$a` `; `
` ` `return` `$x` `; `
`} ` ` ` `// Driver code ` `$a` `= 8; `
`echo` `squareSide(` `$a` `); `
` ` `// This code is contributed by ajit. ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

3.384

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Biggest Reuleaux Triangle inscribed within a square which is inscribed within a hexagon
- Largest hexagon that can be inscribed within an equilateral triangle
- Biggest Reuleaux Triangle inscribed within a Square inscribed in an equilateral triangle
- Biggest Reuleaux Triangle inscribed within a square which is inscribed within an ellipse
- Area of a square inscribed in a circle which is inscribed in an equilateral triangle
- Biggest Reuleaux Triangle within a Square which is inscribed within a Right angle Triangle
- Maximum count of Equilateral Triangles that can be formed within given Equilateral Triangle
- Biggest Square that can be inscribed within an Equilateral triangle
- Largest Square that can be inscribed within a hexagon
- Largest hexagon that can be inscribed within a square
- Largest right circular cylinder that can be inscribed within a cone which is in turn inscribed within a cube
- Largest right circular cone that can be inscribed within a sphere which is inscribed within a cube
- Largest sphere that can be inscribed within a cube which is in turn inscribed within a right circular cone
- Largest ellipse that can be inscribed within a rectangle which in turn is inscribed within a semicircle
- Area of a square inscribed in a circle which is inscribed in a hexagon
- Biggest Reuleaux Triangle within a Square which is inscribed within a Circle
- Area of the Largest Triangle inscribed in a Hexagon
- Area of circle which is inscribed in equilateral triangle
- Area of largest triangle that can be inscribed within a rectangle
- Count of distinct rectangles inscribed in an equilateral triangle

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.