Given a right angled triangle with height **l**, base **b** & hypotenuse **h**.We need to find the area of the largest square that can fit in the right angled triangle.

**Examples:**

Input: l = 3, b = 4, h = 5 Output: 2.93878 The biggest square that can fit inside is of 1.71428 * 1.71428 dimension Input: l = 5, b = 12, h = 13 Output: 12.4567

Considering the above diagram, we see,

tanx = l/b.

Here it is also true that,tanx = a/(b-a).

So,l/b = a/(b-a)which means that,a = (l*b)/(l+b)

**Below is the required implementation:**

## C++

`// C++ Program to find the area of the biggest square ` `// which can fit inside the right angled traingle ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to find the area of the biggest square ` `float` `squareArea(` `float` `l, ` `float` `b, ` `float` `h) ` `{ ` ` ` ` ` `// the height or base or hypotenuse ` ` ` `// cannot be negative ` ` ` `if` `(l < 0 || b < 0 || h < 0) ` ` ` `return` `-1; ` ` ` ` ` `// side of the square ` ` ` `float` `a = (l * b) / (l + b); ` ` ` ` ` `// squaring to get the area ` ` ` `return` `a * a; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `float` `l = 5, b = 12, h = 13; ` ` ` `cout << squareArea(l, b, h) << endl; ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`//Java Program to find the area of the biggest square ` `//which can fit inside the right angled traingle ` `public` `class` `GFG { ` ` ` ` ` `//Function to find the area of the biggest square ` ` ` `static` `float` `squareArea(` `float` `l, ` `float` `b, ` `float` `h) ` ` ` `{ ` ` ` ` ` `// the height or base or hypotenuse ` ` ` `// cannot be negative ` ` ` `if` `(l < ` `0` `|| b < ` `0` `|| h < ` `0` `) ` ` ` `return` `-` `1` `; ` ` ` ` ` `// side of the square ` ` ` `float` `a = (l * b) / (l + b); ` ` ` ` ` `// squaring to get the area ` ` ` `return` `a * a; ` ` ` `} ` ` ` ` ` `//Driver code ` ` ` `public` `static` `void` `main(String[] args) { ` ` ` ` ` `float` `l = ` `5` `, b = ` `12` `, h = ` `13` `; ` ` ` `System.out.println(squareArea(l, b, h)); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## Python 3

`# Python 3 Program to find the ` `# area of the biggest square ` `# which can fit inside the right ` `# angled traingle ` ` ` `# Function to find the area of the biggest square ` `def` `squareArea(l, b, h) : ` ` ` ` ` `# the height or base or hypotenuse ` ` ` `# cannot be negative ` ` ` `if` `l < ` `0` `or` `b < ` `0` `or` `h < ` `0` `: ` ` ` `return` `-` `1` ` ` ` ` `# side of the square ` ` ` `a ` `=` `(l ` `*` `b) ` `/` `(l ` `+` `b) ` ` ` ` ` `# squaring to get the area ` ` ` `return` `a ` `*` `a ` ` ` `# Driver Code ` `if` `__name__ ` `=` `=` `"__main__"` `: ` ` ` ` ` `l, b, h ` `=` `5` `, ` `12` `, ` `13` ` ` ` ` `print` `(` `round` `(squareArea(l, b, h),` `4` `)) ` ` ` `# This code is contributed by ANKITRAI1 ` |

*chevron_right*

*filter_none*

## C#

`// C# Program to find the area of ` `// the biggest square which can ` `// fit inside the right angled triangle ` `using` `System; ` `class` `GFG ` `{ ` ` ` `// Function to find the area ` `// of the biggest square ` `static` `float` `squareArea(` `float` `l, ` `float` `b, ` ` ` `float` `h) ` `{ ` ` ` `// the height or base or hypotenuse ` `// cannot be negative ` `if` `(l < 0 || b < 0 || h < 0) ` ` ` `return` `-1; ` ` ` `// side of the square ` `float` `a = (l * b) / (l + b); ` ` ` `// squaring to get the area ` `return` `a * a; ` `} ` ` ` `// Driver code ` `public` `static` `void` `Main() ` `{ ` ` ` `float` `l = 5, b = 12, h = 13; ` ` ` `Console.WriteLine(squareArea(l, b, h)); ` `} ` `} ` ` ` `// This code is contributed ` `// by inder_verma.. ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP Program to find the area ` `// of the biggest square which ` `// can fit inside the right ` `// angled triangle ` ` ` `// Function to find the area ` `// of the biggest square ` `function` `squareArea(` `$l` `, ` `$b` `, ` `$h` `) ` `{ ` ` ` ` ` `// the height or base or ` ` ` `// hypotenuse cannot be ` ` ` `// negative ` ` ` `if` `(` `$l` `< 0 || ` `$b` `< 0 || ` `$h` `< 0) ` ` ` `return` `-1; ` ` ` ` ` `// side of the square ` ` ` `$a` `= (` `$l` `* ` `$b` `) / (` `$l` `+ ` `$b` `); ` ` ` ` ` `// squaring to get the area ` ` ` `return` `$a` `* ` `$a` `; ` `} ` ` ` `// Driver code ` `$l` `= 5; ` `$b` `= 12; ` `$h` `= 13; ` `echo` `round` `(squareArea(` `$l` `, ` `$b` `, ` `$h` `), 4); ` ` ` `// This code is contributed by mits ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

12.4567

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 within a Square which is inscribed within a Right angle Triangle
- Maximum number of squares that can fit in a right angle isosceles triangle
- Area of Triangle using Side-Angle-Side (length of two sides and the included angle)
- Nth angle of a Polygon whose initial angle and per angle increment is given
- Maximum number of 2x2 squares that can be fit inside a right isosceles triangle
- Find side of Square which makes minimal area to fit two identical rectangles inside it
- Find other two sides of a right angle triangle
- Find other two sides and angles of a right angle triangle
- Angle subtended by the chord when the angle subtended by another chord of same length is given
- Exterior angle of a cyclic quadrilateral when the opposite interior angle is given
- Angle between a chord and a tangent when angle in the alternate segment is given
- Angle subtended by the chord to center of the circle when the angle subtended by the another equal chord of a congruent circle is given
- Program to calculate angle on circumference subtended by the chord when the central angle subtended by the chord is given
- Find all sides of a right angled triangle from given hypotenuse and area | Set 1
- Check if right triangle possible from given area and hypotenuse
- Number of possible pairs of Hypotenuse and Area to form right angled triangle
- Area of Circumcircle of a Right Angled Triangle
- Area of Incircle of a Right Angled Triangle
- Find the height of a right-angled triangle whose area is X times its base
- Biggest Reuleaux Triangle inscribed within a Square 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.