Related Articles
Sum of internal angles of a Polygon
• Last Updated : 04 Nov, 2019

Given an integer N, the task is to find the sum of interior angles of an N-sided polygon. A plane figure having a minimum of three sides and angles is called a polygon.

Examples:

Input: N = 3
Output: 180
3-sided polygon is a triangle and the sum
of the interior angles of a triangle is 180.

Input: N = 6
Output: 720

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Approach: The sum of internal angles of a polygon with N sides is given by (N – 2) * 180

Below is the implementation of the above approach:

## 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

 ``
Output:
```540
```

Attention reader! Don’t stop learning now. Get hold of all the important mathematical concepts for competitive programming with the Essential Maths for CP Course at a student-friendly price. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up