Given a rectangle of length

**Examples**:

Input: L = 5, B = 4 Output: 10 Input: L = 3, B = 2 Output: 3

From the figure, it is clear that the largest triangle that can be inscribed in the rectangle, should stand on the same base & has height raising between the same parallel sides of the rectangle.

So, the base of the triangle = **B**

Height of the triangle = **L**

Therefore Area,

A = (L*B)/2

**Note**: It should also be clear that if base of the triangle = diagonal of rectangle, still the area of triangle so obtained = **lb/2** as diagonal of a rectangle divides it into 2 triangles of equal area.

Below is the implementation of the above approach:

`// C++ Program to find the biggest triangle ` `// which can be inscribed within the rectangle ` `#include <bits/stdc++.h> ` `using` `namespace` `std; `
` ` `// Function to find the area ` `// of the triangle ` `float` `trianglearea(` `float` `l, ` `float` `b) `
`{ ` ` ` ` ` `// a and b cannot be negative `
` ` `if` `(l < 0 || b < 0) `
` ` `return` `-1; `
` ` ` ` `// area of the triangle `
` ` `float` `area = (l * b) / 2; `
` ` `return` `area; `
`} ` ` ` `// Driver code ` `int` `main() `
`{ ` ` ` `float` `l = 5, b = 4; `
` ` `cout << trianglearea(l, b) << endl; `
` ` `return` `0; `
`} ` |

*chevron_right*

*filter_none*

`// Java Program to find the biggest triangle ` `// which can be inscribed within the rectangle ` `import` `java.util.*; `
` ` `class` `GFG `
`{ ` ` ` `// Function to find the area `
` ` `// of the triangle `
` ` `static` `float` `trianglearea(` `float` `l, ` `float` `b) `
` ` `{ `
` ` ` ` `// a and b cannot be negative `
` ` `if` `(l < ` `0` `|| b < ` `0` `) `
` ` `return` `-` `1` `; `
` ` ` ` `// area of the triangle `
` ` `float` `area = (l * b) / ` `2` `; `
` ` `return` `area; `
` ` `} `
` ` ` ` `// Driver code `
` ` `public` `static` `void` `main(String args[]) `
` ` `{ `
` ` `float` `l = ` `5` `, b = ` `4` `; `
` ` ` ` `System.out.println(trianglearea(l, b)); `
` ` `} `
`} ` |

*chevron_right*

*filter_none*

`# Python3 Program to find the ` `# biggest triangle which can be ` `# inscribed within the rectangle ` ` ` `# Function to find the area ` `# of the triangle ` `def` `trianglearea(l, b) : `
` ` ` ` `# a and b cannot be negative `
` ` `if` `(l < ` `0` `or` `b < ` `0` `) : `
` ` `return` `-` `1`
` ` ` ` `# area of the triangle `
` ` `area ` `=` `(l ` `*` `b) ` `/` `2`
` ` `return` `area `
` ` `# Driver code ` `l ` `=` `5`
`b ` `=` `4`
`print` `(trianglearea(l, b)) `
` ` `# This code is contributed ` `# by Yatin Gupta ` |

*chevron_right*

*filter_none*

`// C# Program to find the biggest ` `// triangle which can be inscribed ` `// within the rectangle ` `using` `System; `
` ` `class` `GFG `
`{ ` `// Function to find the area ` `// of the triangle ` `static` `float` `trianglearea(` `float` `l, `
` ` `float` `b) `
`{ ` ` ` ` ` `// a and b cannot be negative `
` ` `if` `(l < 0 || b < 0) `
` ` `return` `-1; `
` ` ` ` `// area of the triangle `
` ` `float` `area = (l * b) / 2; `
` ` `return` `area; `
`} ` ` ` `// Driver code ` `public` `static` `void` `Main() `
`{ ` ` ` `float` `l = 5, b = 4; `
` ` ` ` `Console.WriteLine(trianglearea(l, b)); `
`} ` `} ` ` ` `// This code is contributed ` `// by inder_verma ` |

*chevron_right*

*filter_none*

`<?php ` `// PHP Program to find the biggest ` `// triangle which can be inscribed ` `// within the rectangle ` ` ` `// Function to find the area ` `// of the triangle ` `function` `trianglearea(` `$l` `, ` `$b` `) `
`{ ` ` ` ` ` `// a and b cannot be negative `
` ` `if` `(` `$l` `< 0 ` `or` `$b` `< 0) `
` ` `return` `-1; `
` ` ` ` `// area of the triangle `
` ` `$area` `= (` `$l` `* ` `$b` `) / 2; `
` ` `return` `$area` `; `
`} ` ` ` `// Driver code ` `$l` `= 5; ` `$b` `= 4; `
`echo` `trianglearea(` `$l` `, ` `$b` `); `
` ` `// This code is contributed ` `// by inder_verma ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

10

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:

- Largest ellipse that can be inscribed within a rectangle which in turn is inscribed within a semicircle
- Largest square that can be inscribed within a hexagon which is inscribed within an equilateral triangle
- 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
- 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 inscribed within a Square inscribed in an equilateral triangle
- Biggest Reuleaux Triangle within a Square which is inscribed within a Right angle Triangle
- Area of a triangle inscribed in a rectangle which is inscribed in an ellipse
- Biggest Reuleaux Triangle within a Square which is inscribed within a Circle
- Area of a circle inscribed in a rectangle which is inscribed in a semicircle
- Largest hexagon that can be inscribed within an equilateral triangle
- Area of the biggest ellipse inscribed within a rectangle
- Ratio of area of a rectangle with the rectangle inscribed in it
- Area of Largest rectangle that can be inscribed in an Ellipse
- Area of a square inscribed in a circle which is inscribed in an equilateral triangle
- Maximum area of rectangle inscribed in an equilateral triangle
- Biggest Square that can be inscribed within an Equilateral triangle
- Area of the biggest possible rhombus that can be inscribed in a rectangle

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.