给定一个整数N,代表N边的规则多边形,任务是找到多边形中心上的边所成的角,即圆心角。
The central angle is the angle formed by the two vertices forming an edge and the centre.
例子:
Input: N = 6
Output: 60
Explanation:
The polygon is a hexagon with an angle 60 degree.
Input: N = 5
Output: 72
Explanation:
The polygon is a pentagon with an angle 72 degree.
方法:这个想法是要观察到,由于存在规则的多边形,所以形成的所有圆心角都是相等的。
所有圆心角的总和为360度(一个完整的圆),因此,圆心角的度量为360除以边数。
Hence, central angle = 360 / N degrees, where N is the number of sides.
下面是上述方法的实现:
C++
// C++ program for the above approach
#include
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
Javascript
输出:
72
时间复杂度: O(1)
辅助空间: O(1)