📜  正十边形的对角线

📅  最后修改于: 2021-05-31 19:23:36             🧑  作者: Mango

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

例子:

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

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


Java
// Java program to find the diagonal of a regular decdiagonal
import java.util.*;
import java.lang.*;
import java.io.*;
 
public class GFG {
 
    // Function to return the diagonal of a regular decdiagonal
    static double decdiagonal(double a)
    {
 
//side cannot be negative
        if(a<0)
        return -1;
 
        // length of the diagonal
        double d=1.902*a;
         
        return d;
    }
 
    // Driver code
    public static void main(String[] args)
    {
        int a = 9;
        System.out.println(decdiagonal(a));
    }
}


Python3
# Python3 program to find the diagonal
# of a regular decagon
 
# Function to return the diagonal
# of a regular decagon
def decdiagonal(a) :
 
    # Side cannot be negative
    if (a < 0) :
        return -1
 
    # Length of the diagonal
    d = 1.902 * a
    return d
 
# Driver code
if __name__ == "__main__" :
 
    a = 9
    print(decdiagonal(a))
     
# This code is contributed by Ryuga


C#
// C# program to find the diagonal of a regular decdiagonal
using System;
 
public class GFG {
 
    // Function to return the diagonal of a regular decdiagonal
    static double decdiagonal(double a)
    {
 
//side cannot be negative
        if(a<0)
        return -1;
 
        // length of the diagonal
        double d=1.902*a;
         
        return d;
    }
 
    // Driver code
    public static void Main()
    {
        int a = 9;
        Console.WriteLine(decdiagonal(a));
    }
}
// This code is contributed by anuj_67..


PHP


Javascript


输出:
17.118