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

**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 <bits/stdc++.h> ` `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; ` `} ` |

*chevron_right*

*filter_none*

## 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)); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## 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)); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

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

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation of the approach ` ` ` `// Function to return the sum of internal ` `// angles of an n-sided polygon ` `function` `sumOfInternalAngles(` `$n` `) ` `{ ` ` ` `if` `(` `$n` `< 3) ` ` ` `return` `0; ` ` ` `return` `((` `$n` `- 2) * 180); ` `} ` ` ` `// Driver code ` `$n` `= 5; ` `echo` `(sumOfInternalAngles(` `$n` `)); ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

540

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Check if an N-sided Polygon is possible from N given angles
- Find all angles of a given triangle
- Count of obtuse angles in a circle with 'k' equidistant points between 2 given points
- Program to find smallest difference of angles of two parts of a given circle
- Find all angles of a triangle in 3D
- Find other two sides and angles of a right angle triangle
- Program to find the angles of a quadrilateral
- Check if a triangle of positive area is possible with the given angles
- Check whether the triangle is valid or not if angles are given
- Check whether Quadrilateral is valid or not if angles are given
- Length of remaining two sides of a Triangle from a given side and its adjacent angles
- Internal static variable vs. External static variable with Examples in C
- How to check if a given point lies inside or outside a polygon?
- Minimum Cost Polygon Triangulation
- Area of a polygon with given n ordered vertices
- Polygon Clipping | Sutherlandâ€“Hodgman Algorithm
- Regular polygon using only 1s in a binary numbered circle
- Find number of diagonals in n sided convex polygon
- Minimum area of a Polygon with three points given
- Program to find the Interior and Exterior Angle of a Regular Polygon

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.