# Central angle of a N sided Regular Polygon

Given an integer **N** representing N sided regular polygon, the task is to find the angle made by the sides on the centre of the polygon that is the central angle.

The

central angleis the angle formed by the two vertices forming an edge and the centre.

**Examples: **

Input:N = 6Output:60Explanation:

The polygon is a hexagon with an angle 60 degree.

Input:N = 5Output:72Explanation:

The polygon is a pentagon with an angle 72 degree.

**Approach: **The idea is to observe that since there is a regular polygon all the central angles formed will be equal.

All central angles would add up to 360 degrees (a full circle), so the measure of the central angle is 360 divided by the number of sides.

Hence,

central angle = 360 / N degrees, whereNis the number of sides.

Below is the implementation of the above approach:

## C++

`// C++ program for the above approach` `#include <bits/stdc++.h>` `using` `namespace` `std;` `// Function to calculate central` `// angle of a polygon` `double` `calculate_angle(` `double` `n)` `{` ` ` `// Calculate the angle` ` ` `double` `total_angle = 360;` ` ` `return` `total_angle / n;` `}` `// Driver code` `int` `main()` `{` ` ` `double` `N = 5;` ` ` `cout << calculate_angle(N);` ` ` `return` `0;` `}` |

## Java

`// Java program for the above approach` `class` `GFG{` `// Function to calculate central` `// angle of a polygon` `static` `double` `calculate_angle(` `double` `n)` `{` ` ` ` ` `// Calculate the angle` ` ` `double` `total_angle = ` `360` `;` ` ` `return` `total_angle / n;` `}` `// Driver code` `public` `static` `void` `main(String[] args)` `{` ` ` `double` `N = ` `5` `;` ` ` ` ` `System.out.println(calculate_angle(N));` `}` `}` `// This code is contributed by rock_cool` |

## Python3

`# Python3 program for the above approach` `# Function to calculate central` `# angle of a polygon` `def` `calculate_angle(n):` ` ` `# Calculate the angle` ` ` `total_angle ` `=` `360` `;` ` ` `return` `(total_angle ` `/` `/` `n)` `# Driver code ` `N ` `=` `5` `print` `(calculate_angle(N))` `# This code is contributed by rameshtravel07` |

## C#

`// C# program for the above approach` `using` `System;` `class` `GFG{` `// Function to calculate central` `// angle of a polygon` `static` `double` `calculate_angle(` `double` `n)` `{` ` ` ` ` `// Calculate the angle` ` ` `double` `total_angle = 360;` ` ` `return` `total_angle / n;` `}` `// Driver code` `public` `static` `void` `Main()` `{` ` ` `double` `N = 5;` ` ` ` ` `Console.WriteLine(calculate_angle(N));` `}` `}` `// This code is contributed by Ankita saini` |

## Javascript

`<script>` `// Javascript program for the above approach` `// Function to calculate central` `// angle of a polygon` `function` `calculate_angle(n)` `{` ` ` ` ` `// Calculate the angle` ` ` `var` `total_angle = 360;` ` ` `return` `total_angle / n;` `}` `// Driver code` `var` `N = 5;` ` ` `document.write(calculate_angle(N));` `// This code is contributed by Ankita saini` `</script>` |

**Output:**

72

**Time Complexity:** O(1) **Auxiliary Space:** O(1)

Attention reader! All those who say programming isn’t for kids, just haven’t met the right mentors yet. Join the ** Demo Class for First Step to Coding Course, **specifically **designed for students of class 8 to 12. **

The students will get to learn more about the world of programming in these **free classes** which will definitely help them in making a wise career choice in the future.