📜  求圆柱的周长

📅  最后修改于: 2021-10-23 09:10:54             🧑  作者: Mango

给定直径和高度,求圆柱的周长。
周长是二维形状轮廓的长度。圆柱体是三维形状。因此,从技术上讲,我们无法找到圆柱体的周长,但我们可以找到圆柱体横截面的周长。这可以通过在其底部创建投影来完成,因此,在其侧面创建投影,然后形状将减少为矩形。

公式 :
圆柱周长 ( P ) = ( 2 * d ) + ( 2 * h )
这里 d 是圆柱体的直径
h 是圆柱体的高度
例子 :

Input : diameter = 5, height = 10 
Output : Perimeter = 30

Input : diameter = 50, height = 150 
Output : Perimeter = 400

C++
// CPP program to find
// perimeter of cylinder
#include 
using namespace std;
 
// Function to calculate perimeter
int perimeter(int diameter, int height)
{
    return 2 * (diameter + height);
}
 
// Driver function
int main()
{
    int diameter = 5;
    int height = 10;
     
    cout << "Perimeter = ";
    cout<< perimeter(diameter, height);
    cout<<" units\n";
     
    return 0;
}


Java
// Java program to find
// perimeter of cylinder
import java.io.*;
 
class GFG {
 
    // Function to calculate perimeter
    static int perimeter(int diameter, int height)
    {
        return 2 * (diameter + height);
    }
     
    /* Driver program to test above function */
    public static void main(String[] args)
    {
        int diameter = 5;
        int height = 10;
        System.out.println("Perimeter = " +
                         perimeter(diameter, height)
                                       + " units\n");
    }
}
 
// This code is contributed by Gitanjali.


Python
# Function to calculate
# the perimeter of a cylinder
def perimeter( diameter, height ) :
    return 2 * ( diameter + height )
 
# Driver function
diameter = 5 ;
height = 10 ;
print ("Perimeter = ",
            perimeter(diameter, height))


C#
// C# program to find perimeter of cylinder
using System;
 
class GFG {
 
    // Function to calculate perimeter
    static int perimeter(int diameter, int height)
    {
        return 2 * (diameter + height);
    }
     
    /* Driver program to test above function */
    public static void Main(String[] args)
    {
        int diameter = 5;
        int height = 10;
        Console.Write("Perimeter = " +
                       perimeter(diameter, height)
                                    + " units\n");
    }
}
 
// This code is contributed by parashar...


PHP


Javascript


输出 :

Perimeter = 30 units