📜  查找五角大楼地区的程序

📅  最后修改于: 2021-05-31 21:02:18             🧑  作者: Mango

给定五角大楼的侧面,任务是找到五角大楼的区域。
例子:

Input : a = 5
Output: Area of Pentagon: 43.0119

Input : a = 10
Output: Area of Pentagon: 172.047745

正五边形是五边的几何形状,其所有边和角度均相等。它的内角各为108度,其外角各为72度。五边形的内角的总和为540度。

五角大楼

设a为五角大楼的边,然后用公式求出五角大楼的面积,由
面积= \frac{1}{4}\sqrt{5\left ( 5 + 2\sqrt{5} \right )} a^{2}

C++
// C++ program to find the area of Pentagon
#include
using namespace std;
 
// Function to find area of pentagon
float findArea(float a)
{
    float area;
   
    // Formula to find area
    area = (sqrt(5 * (5 + 2 * (sqrt(5)))) * a * a) / 4;
   
    return area;
}
 
// Driver code
int main()
{
    float a = 5;
     
    // function calling
    cout << "Area of Pentagon: " << findArea(a);
     
    return 0;
}


Java
// Java program to find the area of Pentagon
import java.io.*;
 
class GFG {
     
    // Function to find area of pentagon
    static float findArea(float a)
    {
        float area;
       
        // Formula to find area
        area = (float)(Math.sqrt(5 * (5 + 2
                * (Math.sqrt(5)))) * a * a) / 4;
       
        return area;
    }
     
    // Driver code
    public static void main (String[] args)
    {
        float a = 5;
         
        System.out.println("Area of Pentagon: "
                               + findArea(a));
    }
}


Python3
# Python3 program to find
# the area of Pentagon
 
# Import Math module
# to use sqrt function
from math import sqrt
 
# Function to find
# area of pentagon
 
def findArea(a):
     
    # Formula to find area
    area = (sqrt(5 * (5 + 2 *
           (sqrt(5)))) * a * a) / 4
    return area
     
 
# Driver code
a = 5
 
# call function findArea()
# to calculate area of pentagon
# and print the calculated area
print("Area of Pentagon: ",
               findArea(a))
  
# This code is contributed
# by ihritik


C#
// C# program to find
// the area of Pentagon
using System;
 
class GFG
{
     
    // Function to find
    // area of pentagon
    static float findArea(float a)
    {
        float area;
     
        // Formula to find area
        area = (float)(Math.Sqrt(5 * (5 + 2 *
                      (Math.Sqrt(5)))) *
                             a * a) / 4;
     
        return area;
    }
     
    // Driver code
    public static void Main ()
    {
        float a = 5;
         
        Console.WriteLine("Area of Pentagon: "+
                                  findArea(a));
    }
}
 
// This code is contributed
// by anuj_67.


PHP


Javascript


输出:
Area of Pentagon: 43.0119