# Largest triangle that can be inscribed in a semicircle

Given a semicircle with radius **r**, we have to find the largest triangle that can be inscribed in the semicircle, with base lying on the diameter.

**Examples:**

Input: r = 5 Output: 25 Input: r = 8 Output: 64

**Approach**: From the figure, we can clearly understand the biggest triangle that can be inscribed in the semicircle has height **r**. Also, we know the base has length **2r**. So the triangle is an isosceles triangle.

So, Area

A: = (base * height)/2 =(2r * r)/2 = r^2

**Below is the implementation of above approach**:

## C++

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

*chevron_right*

*filter_none*

## Java

`// Java Program to find the biggest triangle ` `// which can be inscribed within the semicircle ` `import` `java.io.*; ` ` ` `class` `GFG { ` ` ` ` ` `// Function to find the area ` `// of the triangle ` `static` `float` `trianglearea(` `float` `r) ` `{ ` ` ` ` ` `// the radius cannot be negative ` ` ` `if` `(r < ` `0` `) ` ` ` `return` `-` `1` `; ` ` ` ` ` `// area of the triangle ` ` ` `return` `r * r; ` `} ` ` ` `// Driver code ` ` ` ` ` ` ` `public` `static` `void` `main (String[] args) { ` ` ` `float` `r = ` `5` `; ` ` ` `System.out.println( trianglearea(r)); ` ` ` `} ` `} ` `// This code is contributed ` `// by chandan_jnu. ` |

*chevron_right*

*filter_none*

## Python 3

`# Python 3 Program to find the biggest triangle ` `# which can be inscribed within the semicircle ` ` ` `# Function to find the area ` `# of the triangle ` `def` `trianglearea(r) : ` ` ` ` ` `# the radius cannot be negative ` ` ` `if` `r < ` `0` `: ` ` ` `return` `-` `1` ` ` ` ` `# area of the triangle ` ` ` `return` `r ` `*` `r ` ` ` ` ` `# Driver Code ` `if` `__name__ ` `=` `=` `"__main__"` `: ` ` ` ` ` `r ` `=` `5` ` ` `print` `(trianglearea(r)) ` ` ` `# This code is contributed by ANKITRAI1 ` |

*chevron_right*

*filter_none*

## C#

`// C# Program to find the biggest ` `// triangle which can be inscribed ` `// within the semicircle ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `// Function to find the area ` `// of the triangle ` `static` `float` `trianglearea(` `float` `r) ` `{ ` ` ` ` ` `// the radius cannot be negative ` ` ` `if` `(r < 0) ` ` ` `return` `-1; ` ` ` ` ` `// area of the triangle ` ` ` `return` `r * r; ` `} ` ` ` `// Driver code ` `public` `static` `void` `Main () ` `{ ` ` ` `float` `r = 5; ` ` ` `Console.Write(trianglearea(r)); ` `} ` `} ` ` ` `// This code is contributed ` `// by ChitraNayal ` |

*chevron_right*

*filter_none*

## PHP

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

*chevron_right*

*filter_none*

**Output:**

25

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: **DSA Self Paced**. Become industry ready at a student-friendly price.

## Recommended Posts:

- Largest ellipse that can be inscribed within a rectangle which in turn is inscribed within a semicircle
- Biggest Reuleaux Triangle inscirbed within a square inscribed in a semicircle
- Largest square that can be inscribed in a semicircle
- Largest trapezoid that can be inscribed in a semicircle
- Largest rectangle that can be inscribed in a semicircle
- Area of largest Circle that can be inscribed in a SemiCircle
- Largest square that can be inscribed within a hexagon which is inscribed within an equilateral triangle
- Largest triangle that can be inscribed in an ellipse
- 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 Largest Triangle inscribed in a Hexagon
- Area of largest triangle that can be inscribed within a rectangle
- Biggest Reuleaux Triangle inscribed within a Square inscribed in an equilateral triangle
- Biggest Reuleaux Triangle inscribed within a square which is inscribed within a hexagon
- 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
- Area of a triangle inscribed in a rectangle which is inscribed in an ellipse
- Largest right circular cylinder that can be inscribed within a cone which is in turn 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 within a Square which is inscribed within a Right angle 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.