# Biggest Square that can be inscribed within an Equilateral triangle

Given here is an equilateral triangle of side length **a**. The task is to find the side of the biggest square that can be inscribed within it.

**Examples:**

Input:a = 5Output:2.32Input:a = 7Output:3.248

**Approach**: Let the side of the square be **x**.

Now, **AH** is perpendicular to **DE**.

**DE** is parallel to **BC**, So, angle **AED = angle ACB = 60**

In triangleEFC, => Sin60 = x/ EC => √3 / 2 = x/EC => EC = 2x/√3 In triangleAHE, => Cos 60 = x/2AE => 1/2 = x/2AE => AE = x

So, side **AC** of the triangle = **2x/√3 + x**. Now,

**a = 2x/√3 + x**

Therefore, **x = a/(1 + 2/√3) = 0.464a**

Below is the implementation of the above approach:

## C++

`// C++ Program to find the biggest square ` `// which can be inscribed within the equilateral triangle ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to find the side ` `// of the square ` `float` `square(` `float` `a) ` `{ ` ` ` ` ` `// the side cannot be negative ` ` ` `if` `(a < 0) ` ` ` `return` `-1; ` ` ` ` ` `// side of the square ` ` ` `float` `x = 0.464 * a; ` ` ` ` ` `return` `x; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `float` `a = 5; ` ` ` `cout << square(a) << endl; ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java Program to find the ` `// the biggest square which ` `// can be inscribed within ` `// the equilateral triangle ` ` ` `class` `GFG ` `{ ` ` ` `// Function to find the side ` ` ` `// of the square ` ` ` `static` `double` `square(` `double` `a) ` ` ` `{ ` ` ` ` ` `// the side cannot be negative ` ` ` `if` `(a < ` `0` `) ` ` ` `return` `-` `1` `; ` ` ` ` ` `// side of the square ` ` ` `double` `x = ` `0.464` `* a; ` ` ` `return` `x; ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `main(String []args) ` ` ` `{ ` ` ` `double` `a = ` `5` `; ` ` ` `System.out.println(square(a)); ` ` ` `} ` `} ` ` ` `// This code is contributed by ihritik ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 Program to find the biggest square ` `# which can be inscribed within the equilateral triangle ` ` ` `# Function to find the side ` `# of the square ` `def` `square( a ): ` ` ` ` ` ` ` `# the side cannot be negative ` ` ` `if` `(a < ` `0` `): ` ` ` `return` `-` `1` ` ` ` ` `# side of the square ` ` ` `x ` `=` `0.464` `*` `a ` ` ` ` ` `return` `x ` ` ` ` ` `# Driver code ` `a ` `=` `5` `print` `(square(a)) ` ` ` `# This code is contributed by ihritik ` |

*chevron_right*

*filter_none*

## C#

`// C# Program to find the biggest ` `// square which can be inscribed ` `// within the equilateral triangle ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `// Function to find the side ` ` ` `// of the square ` ` ` `static` `double` `square(` `double` `a) ` ` ` `{ ` ` ` ` ` `// the side cannot be negative ` ` ` `if` `(a < 0) ` ` ` `return` `-1; ` ` ` ` ` `// side of the square ` ` ` `double` `x = 0.464 * a; ` ` ` `return` `x; ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `Main() ` ` ` `{ ` ` ` `double` `a = 5; ` ` ` `Console.WriteLine(square(a)); ` ` ` `} ` `} ` ` ` `// This code is contributed by ihritik ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP Program to find the biggest ` `// square which can be inscribed ` `// within the equilateral triangle ` ` ` `// Function to find the side ` `// of the square ` `function` `square(` `$a` `) ` `{ ` ` ` ` ` `// the side cannot be negative ` ` ` `if` `(` `$a` `< 0) ` ` ` `return` `-1; ` ` ` ` ` `// side of the square ` ` ` `$x` `= 0.464 * ` `$a` `; ` ` ` `return` `$x` `; ` `} ` ` ` `// Driver code ` `$a` `= 5; ` `echo` `square(` `$a` `); ` ` ` `// This code is contributed by ihritik ` ` ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

2.32

## Recommended Posts:

- 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
- Largest square that can be inscribed within a hexagon which is inscribed within an equilateral triangle
- 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
- Biggest Reuleaux Triangle within a Square which is inscribed within a Right angle Triangle
- Biggest Reuleaux Triangle within a Square which is inscribed within a Circle
- Biggest Reuleaux Triangle inscirbed within a square inscribed in a semicircle
- Area of circle which is inscribed in equilateral triangle
- Largest hexagon that can be inscribed within an equilateral triangle
- Count of distinct rectangles inscribed in an equilateral triangle
- Biggest Reuleaux Triangle within A Square
- Radius of the biggest possible circle inscribed in rhombus which in turn is inscribed in a rectangle
- Area of a triangle inscribed in a rectangle which is inscribed in an ellipse
- Area of a square inscribed in a circle which is inscribed in a hexagon

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.