📜  多边形的内角总和

📅  最后修改于: 2021-04-21 23:20:09             🧑  作者: Mango

给定整数N ,任务是找到N边多边形的内角之和。至少具有三个边和三个角度的平面图形称为多边形。

例子:

方法:具有N个边的多边形的内角之和为(N – 2)* 180

下面是上述方法的实现:

C++
// C++ implementation of the approach
#include 
using namespace std;
  
// Function to return the sum of internal
// angles of an n-sided polygon
int sumOfInternalAngles(int n)
{
    if (n < 3)
        return 0;
    return (n - 2) * 180;
}
  
// Driver code
int main()
{
    int n = 5;
  
    cout << sumOfInternalAngles(n);
  
    return 0;
}


Java
// Java implementation of the approach
class GFG {
  
    // Function to return the sum of internal
    // angles of an n-sided polygon
    static int sumOfInternalAngles(int n)
    {
        if (n < 3)
            return 0;
        return ((n - 2) * 180);
    }
  
    // Driver code
    public static void main(String args[])
    {
        int n = 5;
  
        System.out.print(sumOfInternalAngles(n));
    }
}


C#
// C# implementation of the approach
using System;
class GFG {
  
    // Function to return the sum of internal
    // angles of an n-sided polygon
    static int sumOfInternalAngles(int n)
    {
        if (n < 3)
            return 0;
        return ((n - 2) * 180);
    }
  
    // Driver code
    public static void Main()
    {
        int n = 5;
  
        Console.Write(sumOfInternalAngles(n));
    }
}


Python
# Python3 implementation of the approach
  
# Function to return the sum of internal 
# angles of an n-sided polygon
def sumOfInternalAngles(n):
    if(n < 3):
        return 0
    return ((n - 2) * 180)
  
# Driver code
n = 5
print(sumOfInternalAngles(n))


PHP


输出:
540