给定角度在哪里, 。任务是检查是否有可能制作一个规则多边形,使其所有内角等于 。如果可能,然后打印“是”,否则打印“否”(不带引号)。
例子:
Input: angle = 90
Output: YES
Polygons with sides 4 is
possible with angle 90 degrees.
Input: angle = 30
Output: NO
方法:内角定义为规则多边形的任意两个相邻边之间的角度。
它是由其中, n是多边形中的边数。
这可以写成 。
经过重新安排,我们得到了, 。
因此,如果n为整数,则答案为“是”,否则答案为“否”。
下面是上述方法的实现:
C++
// C++ implementation of above approach
#include
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 code
int main()
{
float a = 90;
// function to print the required answer
makePolygon(a);
return 0;
}
Java
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 code
public static void main (String[] args)
{
double a = 90;
// function to print
// the required answer
makePolygon(a);
}
}
// This code is contributed by Bilal
Python3
# 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 Code
if __name__ == "__main__" :
a = 90
# function calling
makePolygon(a)
# This code is contributed
# by ANKITRAI1
C#
// C# implementation of
// above approach
using 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 code
static void Main()
{
double a = 90;
// function to print
// the required answer
makePolygon(a);
}
}
// This code is contributed by mits
PHP
输出:
YES