📜  正五边形的对角线

📅  最后修改于: 2021-04-24 04:52:51             🧑  作者: Mango

给定整数a是规则五边形的边,任务是查找并打印其对角线的长度。

例子:

方法:我们知道多边形的内角总和= (n – 2)* 180 ,其中, n为否。多边形中的边数。
因此,五边形的内角之和= 3 * 180 = 540 ,每个内角将为108
现在,我们必须找到BC = 2 * x 。如果在BC上绘制垂直AO ,我们将看到BOOC中的垂直二等分BC ,因为三角形AOBAOC彼此相等。
因此,在三角形AOB中sin(54)= x / ax = 0.61 * a
因此,对角线长度将为2 * x,1.22 * a
下面是上述方法的实现:

C++
// C++ Program to find the diagonal
// of a regular pentagon
#include 
using namespace std;
 
// Function to find the diagonal
// of a regular pentagon
float pentdiagonal(float a)
{
 
    // Side cannot be negative
    if (a < 0)
        return -1;
 
    // Length of the diagonal
    float d = 1.22 * a;
    return d;
}
 
// Driver code
int main()
{
    float a = 6;
    cout << pentdiagonal(a) << endl;
    return 0;
}


Java
// Java Program to find the diagonal
// of a regular pentagon
class GFG
{
     
// Function to find the diagonal
// of a regular pentagon
static double pentdiagonal(double a)
{
 
    // Side cannot be negative
    if (a < 0)
        return -1;
 
    // Length of the diagonal
    double d = 1.22 * a;
    return d;
}
 
// Driver code
static public void main (String args[])
{
    double a = 6;
    System.out.println(pentdiagonal(a));
}
}
 
// This code is contributed
// by Akanksha Rai


Python3
# Python3 Program to find the diagonal
# of a regular pentagon
 
# Function to find the diagonal
# of a regular pentagon
def pentdiagonal(a) :
 
    # Side cannot be negative
    if (a < 0) :
        return -1
 
    # Length of the diagonal
    d = 1.22 * a
    return d
 
# Driver code
if __name__ == "__main__" :
 
    a = 6
    print(pentdiagonal(a))
 
# This code is contributed by Ryuga


C#
// C# Program to find the diagonal
// of a regular pentagon
using System;
 
public class GFG{
     
// Function to find the diagonal
// of a regular pentagon
static double pentdiagonal(double a)
{
 
    // Side cannot be negative
    if (a < 0)
        return -1;
 
    // Length of the diagonal
    double d = 1.22 * a;
    return d;
}
 
// Driver code
    static public void Main (){
    double a = 6;
    Console.WriteLine(pentdiagonal(a));
    }
}


PHP


Javascript


输出:
7.32