📜  计算给定对角线的五边形面积

📅  最后修改于: 2021-04-24 04:11:56             🧑  作者: Mango

给定整数d ,它是五边形的对角线的长度,任务是找到该五边形的面积。

五角大楼

例子:

方法:五角大楼是一个规则的多边形,具有五个相等的边和所有相等的角度。五边形的内角各为108度,五边形的所有角之和为540度。如果d是五边形的对角线,则其面积由下式给出:

    $$ \frac{1}{8} {d^2 (-5+ \sqrt{45})\sqrt{ \sqrt{20} + 5 } } $$

下面是上述方法的实现:

C++
// C++ program to find the area of
// Pentagon with given diagonal
#include 
using namespace std;
 
// Function to return the area of the
// pentagon with diagonal d
float pentagonArea(float d)
{
    float area;
 
    // Formula to find area
    area = (d * d * (-5 + sqrt(45)) * sqrt(sqrt(20) + 5)) / 8;
 
    return area;
}
 
// Driver code
int main()
{
    float d = 5;
    cout << pentagonArea(d);
    return 0;
}


Java
// Java program to find the area of
// Pentagon with given diagonal
import java.text.*;
class GFG{
// Function to return the area of the
// pentagon with diagonal d
static double pentagonArea(double d)
{
    double area;
 
    // Formula to find area
    area = (d * d * (-5 + Math.sqrt(45)) * Math.sqrt(Math.sqrt(20) + 5)) / 8;
 
    return area;
}
 
// Driver code
public static void main(String[] args)
{
    double d = 5;
    DecimalFormat dec = new DecimalFormat("#0.0000");
    System.out.println(dec.format(pentagonArea(d)));
}
}
// This code is contributed by mits


Python3
# Python3 program to find the area of
# Pentagon with given diagonal
 
# from math lib import sqrt() method
from math import sqrt
 
# Function to return the area of the
# pentagon with diagonal d
def pentagonArea(d) :
 
    # Formula to find area
    area = (d * d * (-5 + sqrt(45)) * sqrt(sqrt(20) + 5)) / 8
 
    return round(area , 4)
  
 
# Driver code
if __name__ == "__main__" :
 
    d = 5
    print(pentagonArea(d))
 
# This code is contributed by Ryuga


C#
// C# program to find the area of
// Pentagon with given diagonal
using System;
 
class GFG{
// Function to return the area of the
// pentagon with diagonal d
static double pentagonArea(double d)
{
    double area;
 
    // Formula to find area
    area = (d * d * (-5 + Math.Sqrt(45)) * Math.Sqrt(Math.Sqrt(20) + 5)) / 8;
 
    return area;
}
 
// Driver code
public static void Main()
{
    double d = 5;
    Console.WriteLine("{0:F4}",pentagonArea(d));
}
}
// This code is contributed by mits


PHP


Javascript


输出:
16.4291