Program to find the Interior and Exterior Angle of a Regular Polygon - GeeksforGeeks

19 Mar, 2021
Given the number of sides n of a regular polygon. The task is to find out the Interior angle and Exterior angle of the polygon.Examples:  
Input : n = 6
Output : Interior angle: 120
         Exterior angle: 60

Input : n = 10
Output: Interior angle: 144
        Exterior angle: 36
 
Interior angle: The angle between two adjacent sides inside the polygon is known as the Interior angle. Formula to find the Interior angle:Interior Angle = Exterior angle: The angle formed by any side of a polygon and the extension of its adjacent side is known as Exterior angle.Exterior angle =  
Program to find interior and exterior angles of a Regular Polygon:  
C++
Java
Python3
C#
PHP
Javascript
// CPP program to find the interior and// exterior angle of a given polygon#include <iostream>using namespace std; // function to find the interior and// exterior anglevoid findAngle(int n){    int interiorAngle, exteriorAngle;     // formula to find the interior angle    interiorAngle = (n - 2) * 180 / n;         // formula to find the exterior angle    exteriorAngle = 360 / n;     // Displaying the output    cout << "Interior angle: " << interiorAngle << endl;     cout << "Exterior angle: " << exteriorAngle;} // Driver codeint main(){    int n = 10;         // Function calling    findAngle(n);    return 0;}
// Java program to find the interior and// exterior angle of a given polygonimport java.io.*; class GFG {         // function to find the interior and    // exterior angle    static void findAngle(int n)    {        int interiorAngle, exteriorAngle;             // formula to find the interior angle        interiorAngle = (n - 2) * 180 / n;                 // formula to find the exterior angle        exteriorAngle = 360 / n;             // Displaying the output        System.out.println("Interior angle: " + interiorAngle);             System.out.println("Exterior angle: " + exteriorAngle);    }         // Driver code    public static void main (String[] args)    {        int n = 10;             // Function calling        findAngle(n);    }}
# Python3 program to find# the interior and exterior# angle of a given polygon # function to find# the interior and# exterior angledef findAngle(n):     # formula to find the    # interior angle    interiorAngle = int((n - 2) * 180 / n)         # formula to find    # the exterior angle    exteriorAngle = int(360 / n)     # Displaying the output    print("Interior angle: " ,            interiorAngle )     print("Exterior angle: " ,           exteriorAngle ) # Driver coden = 10     # Function callingfindAngle(n) # This code is contributed# by Smitha
// C# program to find the// interior and exterior// angle of a given polygonusing System; class GFG{         // function to find    // the interior and    // exterior angle    static void findAngle(int n)    {        int interiorAngle,            exteriorAngle;             // formula to find        // the interior angle        interiorAngle = (n - 2) * 180 / n;                 // formula to find        // the exterior angle        exteriorAngle = 360 / n;             // Displaying the output        Console.Write("Interior angle: " +                    interiorAngle + "\n");             Console.Write("Exterior angle: " +                           exteriorAngle);    }         // Driver code    public static void Main ()    {        int n = 10;             // Function calling        findAngle(n);    }} // This code is contributed// by Smitha
<?php// PHP program to find the// interior and exterior// angle of a given polygon // function to find the// interior and exterior// anglefunction findAngle($n){    $interiorAngle;    $exteriorAngle;     // formula to find    // the interior angle    $interiorAngle = ($n - 2) *                      180 / $n;         // formula to find    // the exterior angle    $exteriorAngle = 360 /$n;     // Displaying the output    echo "Interior angle: " ,          $interiorAngle, "\n" ;     echo "Exterior angle: " ,          $exteriorAngle;} // Driver code$n = 10; // Function callingfindAngle($n); // This code is contributed// by inder_verma.?>
<script>// JavaScript program to find the interior and// exterior angle of a given polygon // function to find the interior and// exterior anglefunction findAngle(n){    let interiorAngle, exteriorAngle;     // formula to find the interior angle    interiorAngle = Math.floor((n - 2) * 180 / n);         // formula to find the exterior angle    exteriorAngle = Math.floor(360 / n);     // Displaying the output    document.write("Interior angle: " + interiorAngle + "<br>");     document.write("Exterior angle: " + exteriorAngle);} // Driver code    let n = 10;         // Function calling    findAngle(n); // This code is contributed by Surbhi Tyagi.</script>
Interior angle: 144
Exterior angle: 36
 
Smitha Dinesh Semwal
inderDuMCA
surbhityagi15
math
Mathematical
School Programming
Mathematical
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Merge two sorted arrays
Modulo Operator (%) in C/C++ with Examples
Prime Numbers
Program for factorial of a number
Print all possible combinations of r elements in a given array of size n
Python Dictionary
Arrays in C/C++
Inheritance in C++
Reverse a string in Java
C++ Classes and Objects