📜  程序来查找规则多边形的周长

📅  最后修改于: 2021-05-04 09:49:38             🧑  作者: Mango

给定规则多边形的边数“ n”和边长“ s”,任务是找出此多边形的周长。

例子:

Input: n = 7, s = 10
Output: Perimeter : 70
Since the sides are 7,
Hence the given polygon is Heptagon.
Therefore. Perimeter = 7*10 = 70

Input: n = 5, s = 2.5
Output: Perimeter : 12.5
Since the sides are 5,
Hence the given polygon is Pentagon.
Therefore. Perimeter = 5*2.5 = 12.5

方法:在几何图形中,规则多边形是一个封闭的图形,所有面都是相等的。这是一个二维图。

下面是上述方法的实现:

C++
// C++ program to find the
// perimeter of a regular polygon
 
#include 
using namespace std;
 
// Function to calculate the perimeter
float Perimeter(float s, int n)
{
    float perimeter = 1;
 
    // Calculate Perimeter
    perimeter = n * s;
 
    return perimeter;
}
 
// driver code
int main()
{
 
    // Get the number of sides
    int n = 5;
 
    // Get the length of side
    float s = 2.5, peri;
 
    // find perimeter
    peri = Perimeter(s, n);
 
    cout << "Perimeter of Regular Polygon"
         << " with " << n << " sides of length "
         << s << " = " << peri << endl;
 
    return 0;
}


C
// C program to find the
// perimeter of a regular polygon
 
#include 
 
// Function to calculate the perimeter
float Perimeter(float s, int n)
{
    float perimeter = 1;
 
    // Calculate Perimeter
    perimeter = n * s;
 
    return perimeter;
}
 
// driver code
int main()
{
 
    // Get the number of sides
    int n = 5;
 
    // Get the length of side
    float s = 2.5, peri;
 
    // find perimeter
    peri = Perimeter(s, n);
 
    printf("Perimeter of Regular Polygon\n"
           " with %d sides of length %f = %f\n",
           n, s, peri);
 
    return 0;
}


Java
// Java program to find the
// perimeter of a regular polygon
 
class GFG {
 
    // Function to calculate the perimeter
    static double Perimeter(double s, int n)
    {
        double perimeter = 1;
 
        // Calculate Perimeter
        perimeter = n * s;
 
        return perimeter;
    }
 
    // Driver method
    public static void main(String[] args)
    {
 
        // Get the number of sides
        int n = 5;
 
        // Get the length of side
        double s = 2.5, peri;
 
        // find perimeter
        peri = Perimeter(s, n);
 
        System.out.println("Perimeter of Regular Polygon"
                           + " with " + n + " sides of length "
                           + s + " = " + peri);
    }
}


Python3
# Python3 program to find the
# perimeter of a regular polygon
 
 
# Function to calculate the perimeter
def Perimeter(s, n):
    perimeter = 1
    # Calculate Perimeter
    perimeter = n * s
 
    return perimeter
 
# driver code
if __name__== '__main__':
    # Get the number of sides
    n = 5
 
    #Get the length of side
    s = 2.5
    # find perimeter
    peri = Perimeter(s, n)
 
    print("Perimeter of Regular Polygon with"
          ,n,"sides of length",s,"=",peri)
     
# This code is contributed by
# SURENDRA_GANGWAR


C#
// C# program to find the
// perimeter of a regular polygon
using System;
 
class GFG
{
// Function to calculate the perimeter
static double Perimeter(double s, int n)
{
    double perimeter = 1;
 
    // Calculate Perimeter
    perimeter = n * s;
 
    return perimeter;
}
 
// Driver Code
static public void Main ()
{
    // Get the number of sides
    int n = 5;
 
    // Get the length of side
    double s = 2.5, peri;
 
    // find perimeter
    peri = Perimeter(s, n);
 
    Console.WriteLine("Perimeter of Regular Polygon" +
                      " with " + n + " sides of length " +
                        s + " = " + peri);
}
}
 
// This code is contributed by Sachin


PHP


Javascript


输出:
Perimeter of Regular Polygon 
with 5 sides of length 2.500000 = 12.500000