Maximum area of rectangle inscribed in an equilateral triangle

24 Mar, 2021
Given an integer A, which denotes the side of an equilateral triangle, the task is to find the maximum area of the rectangle that can be inscribed in the triangle.Examples:  
Input: A = 10 Output: 21.65 Explanation: Maximum area of rectangle inscribed in an equilateral triangle of side 10 is 21.65.Input: A = 12 Output: 31.176 Explanation: Maximum area of rectangle inscribed in an equilateral triangle of side 12 is 31.176.  
 
Approach: The idea is to use the fact that interior angles of an equilateral triangle is 60o. Then, Draw the perpendicular from one of the side of the triangle and compute the sides of the rectangle with the help of below formulae  
The length of Rectangle = (Side of Equilateral Triangle)/2The breadth of Rectangle = sqrt(3) * (Side of Equilateral Triangle)/4  
Then, Maximum area of the rectangle will be Below is the implementation of the above approach:  
C++
Java
Python3
C#
Javascript
// CPP implementation to find the// maximum area inscribed in an// equilateral triangle#include<bits/stdc++.h>using namespace std; // Function to find the maximum area// of the rectangle inscribed in an// equilateral triangle of side Sdouble 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 Codeint main(){    int n = 14;    cout << solve(n);}     // This code is contributed by Surendra_Gangwar
// 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 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 Sdef solve(s):         # Maximum area of the rectangle    # inscribed in an equilateral    # triangle of side S    area = (1.732 * s**2)/8    return area          # Driver Codeif __name__=='__main__':    n = 14    print(solve(n))
// C# implementation to find the// maximum area inscribed in an// equilateral triangleusing 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
<script> // Javascript 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 Sfunction solve(s){     // Maximum area of the rectangle    // inscribed in an equilateral    // triangle of side S    let area = (1.732 * Math.pow(s, 2))/8;    return area;     }     // Driver Code    let n = 14;    document.write(solve(n)); // This code is contributed by Manoj </script>
42.434
 
SURENDRA_GANGWAR
ApurvaRaj
Rajput-Ji
mank1083
Geometric
Mathematical
Mathematical
Geometric
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.