📜  等边三角形内接矩形的最大面积

📅  最后修改于: 2021-10-23 09:06:24             🧑  作者: Mango

给定一个整数A ,它表示等边三角形的边,任务是找到可以内接在三角形中的矩形的最大面积。
例子:

方法:这个想法是利用等边三角形的内角是 60 o的事实。然后,从三角形的边之一绘制垂线并借助以下公式计算矩形的边

然后,矩形的最大面积将是\sqrt 3 * \frac {A^2}{8}
下面是上述方法的实现:

C++
// CPP implementation to find the
// maximum area inscribed in an
// equilateral triangle
#include
using namespace std;
 
// Function to find the maximum area
// of the rectangle inscribed in an
// equilateral triangle of side S
double solve(int s)
{
    // Maximum area of the rectangle
    // inscribed in an equilateral
    // triangle of side S
    double area = (1.732 * pow(s, 2))/8;
    return area;
     
}
     
// Driver Code
int main()
{
    int n = 14;
    cout << solve(n);
}
     
// This code is contributed by Surendra_Gangwar


Java
// Java implementation to find the
// maximum area inscribed in an
// equilateral triangle
 
class GFG
{
    // Function to find the maximum area
    // of the rectangle inscribed in an
    // equilateral triangle of side S
    static double solve(int s)
    {
        // Maximum area of the rectangle
        // inscribed in an equilateral
        // triangle of side S
        double area = (1.732 * Math.pow(s, 2))/8;
        return area;
     
    }
     
    // Driver Code
    public static void  main(String[] args)
    {
        int n = 14;
        System.out.println(solve(n));
    }
}
     
// This article is contributed by Apurva raj


Python3
# Python3 implementation to find the
# maximum area inscribed in an
# equilateral triangle
 
# Function to find the maximum area
# of the rectangle inscribed in an
# equilateral triangle of side S
def solve(s):
     
    # Maximum area of the rectangle
    # inscribed in an equilateral
    # triangle of side S
    area = (1.732 * s**2)/8
    return area
     
     
# Driver Code
if __name__=='__main__':
    n = 14
    print(solve(n))


C#
// C# implementation to find the
// maximum area inscribed in an
// equilateral triangle
using System;
 
class GFG
{
    // Function to find the maximum area
    // of the rectangle inscribed in an
    // equilateral triangle of side S
    static double solve(int s)
    {
        // Maximum area of the rectangle
        // inscribed in an equilateral
        // triangle of side S
        double area = (1.732 * Math.Pow(s, 2))/8;
        return area;
      
    }
      
    // Driver Code
    public static void  Main(String[] args)
    {
        int n = 14;
        Console.WriteLine(solve(n));
    }
}
 
// This code is contributed by Rajput-Ji


Javascript


输出:
42.434

如果您希望与专家一起参加现场课程,请参阅DSA 现场工作专业课程学生竞争性编程现场课程