📜  正十边形的对角线

📅  最后修改于: 2021-10-23 08:28:52             🧑  作者: 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 * x1.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

如果您希望与专家一起参加现场课程,请参阅DSA 现场工作专业课程学生竞争性编程现场课程