Check if it is possible to create a polygon with a given angle - GeeksforGeeks

03 May, 2021
Given an angle where, . The task is to check whether it is possible to make a regular polygon with all of its interior angle equal to . If possible then print “YES”, otherwise print “NO” (without quotes). Examples:  
Input: angle = 90
Output: YES
Polygons with sides 4 is
possible with angle 90 degrees.

Input: angle = 30
Output: NO
 
Approach: The Interior angle is defined as the angle between any two adjacent sides of a regular polygon.It is given by     where, n is the number of sides in the polygon.This can be written as   .On rearranging terms we get,   .Thus, if n is an Integer the answer is “YES” otherwise, answer is “NO”.Below is the implementation of the above approach:  
C++
Java
Python3
C#
PHP
Javascript
// C++ implementation of above approach#include <bits/stdc++.h>using namespace std; // Function to check whether it is possible// to make a regular polygon with a given angle.void makePolygon(float a){    // N denotes the number of sides    // of polygons possible    float n = 360 / (180 - a);    if (n == (int)n)        cout << "YES";    else        cout << "NO";} // Driver codeint main(){    float a = 90;     // function to print the required answer    makePolygon(a);     return 0;}
class GFG{// Function to check whether// it is possible to make a// regular polygon with a given angle.static void makePolygon(double a){    // N denotes the number of    // sides of polygons possible    double n = 360 / (180 - a);    if (n == (int)n)        System.out.println("YES");    else        System.out.println("NO");} // Driver codepublic static void main (String[] args){    double a = 90;     // function to print    // the required answer    makePolygon(a);}} // This code is contributed by Bilal
# Python 3 implementation# of above approach # Function to check whether# it is possible to make a# regular polygon with a# given angle.def makePolygon(a) :     # N denotes the number of sides    # of polygons possible    n = 360 / (180 - a)     if n == int(n) :        print("YES")     else :        print("NO") # Driver Codeif __name__ == "__main__" :    a = 90     # function calling    makePolygon(a)     # This code is contributed# by ANKITRAI1
// C# implementation of// above approachusing System; class GFG{// Function to check whether// it is possible to make a// regular polygon with a// given angle.static void makePolygon(double a){    // N denotes the number of    // sides of polygons possible    double n = 360 / (180 - a);    if (n == (int)n)        Console.WriteLine("YES");    else        Console.WriteLine("NO");} // Driver codestatic void Main(){    double a = 90;     // function to print    // the required answer    makePolygon(a);}} // This code is contributed by mits
<?php// PHP implementation of above approach // Function to check whether it// is possible to make a regular// polygon with a given angle.function makePolygon($a){    // N denotes the number of    // sides of polygons possible    $n = 360 / (180 - $a);    if ($n == (int)$n)        echo "YES";    else        echo "NO";} // Driver code$a = 90; // function to print the// required answermakePolygon($a); // This code is contributed// by ChitraNayal?>
<script>       // JavaScript implementation of above approach      // Function to check whether it is possible      // to make a regular polygon with a given angle.             function makePolygon(a)      {        // N denotes the number of sides        // of polygons possible        var n = parseFloat(360 / (180 - a));        if (n === parseInt(n))        document.write("YES");        else        document.write("NO");      }       // Driver code      var a = 90;             // function to print the required answer      makePolygon(a);       </script>
YES
 
bilal-hungund
Mithun Kumar
ankthon
ukasp
rdtank
math
Geometric
Mathematical
School Programming
Mathematical
Geometric
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Program for distance between two points on earth
Convex Hull | Set 1 (Jarvis's Algorithm or Wrapping)
Convex Hull | Set 2 (Graham Scan)
Given n line segments, find if any two segments intersect
Closest Pair of Points | O(nlogn) Implementation
Program for Fibonacci numbers
Write a program to print all permutations of a given string
C++ Data Types
Set in C++ Standard Template Library (STL)
Coin Change | DP-7