📌  相关文章
📜  可以刻在半圆上的最大三角形

📅  最后修改于: 2021-04-24 16:37:47             🧑  作者: Mango

给定半径为r的半圆形,我们必须找到可以在半圆形中内接的最大三角形,其底数位于直径上。
例子:

Input: r = 5
Output: 25

Input: r = 8
Output: 64

方法:从图中,我们可以清楚地了解到可以在半圆上切出的最大三角形的高度为r 。另外,我们知道基座的长度为2r 。因此,该三角形是等腰三角形。

下面是上述方法的实现

C++
// C++ Program to find the biggest triangle
// which can be inscribed within the semicircle
#include 
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;
}


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.


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


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


PHP


Javascript


输出:
25