检查是否可以创建具有给定角度的多边形

给定角度 a  哪里 1le a< 180  .任务是检查是否有可能使正多边形的所有内角都等于 a  .如果可能,则打印“是”,否则打印“否”(不带引号)。 例如:

null
Input: angle = 90Output: YESPolygons with sides 4 ispossible with angle 90 degrees.Input: angle = 30Output: NO

方法: 内角定义为正多边形任意两个相邻边之间的角度。 它由 ;Interior;angle = frac{180 	imes (n-2)}{n};  哪里 N 是多边形中的边数。 这可以写成 ;a = frac{180 	imes (n-2)}{n};  . 根据我们得到的重新安排条件, ;n = frac{360}{180 - a};  . 因此,如果 N 是一个 整数 答案是“是”,否则答案是“否”。 以下是上述方法的实施情况:

C++

// 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 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

<?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 answer
makePolygon( $a );
// This code is contributed
// by ChitraNayal
?>


Javascript

<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

© 版权声明
THE END
喜欢就支持一下吧
点赞8 分享