📌  相关文章
📜  查找正多边形的内部和外部角度的程序

📅  最后修改于: 2021-04-24 17:17:17             🧑  作者: Mango

给定规则多边形的边数n。任务是找出多边形的内角和外角。
例子

Input : n = 6
Output : Interior angle: 120
         Exterior angle: 60

Input : n = 10
Output: Interior angle: 144
        Exterior angle: 36

内角:多边形内两个相邻边之间的角度称为内角。
查找内角的公式:
内角= \frac{(n-2)\times 180}{n}
外角:多边形任意一侧与其相邻边的延长线所形成的角度称为外角。
外角= \frac{360}{n}

内外角

查找正多边形的内部和外部角度的程序:

C++
// CPP program to find the interior and
// exterior angle of a given polygon
#include 
using namespace std;
 
// function to find the interior and
// exterior angle
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
    cout << "Interior angle: " << interiorAngle << endl;
 
    cout << "Exterior angle: " << exteriorAngle;
}
 
// Driver code
int main()
{
    int n = 10;
     
    // Function calling
    findAngle(n);
    return 0;
}


Java
// Java program to find the interior and
// exterior angle of a given polygon
import 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
# Python3 program to find
# the interior and exterior
# angle of a given polygon
 
# function to find
# the interior and
# exterior angle
def 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 code
n = 10
     
# Function calling
findAngle(n)
 
# This code is contributed
# by Smitha


C#
// C# program to find the
// interior and exterior
// angle of a given polygon
using 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


Javascript


输出:
Interior angle: 144
Exterior angle: 36