Find the perimeter of a cylinder
Last Updated :
20 Feb, 2023
Given diameter and height, find the perimeter of a cylinder.
Perimeter is the length of the outline of a two – dimensional shape. A cylinder is a three – dimensional shape. So, technically we cannot find the perimeter of a cylinder but we can find the perimeter of the cross-section of the cylinder. This can be done by creating the projection on its base, thus, creating the projection on its side, then the shape would be reduced to a rectangle.

Formula :
Perimeter of cylinder ( P ) = 
here d is the diameter of the cylinder
h is the height of the cylinder
Examples :
Input : diameter = 5, height = 10
Output : Perimeter = 30
Input : diameter = 50, height = 150
Output : Perimeter = 400
C++
#include <iostream>
using namespace std;
int perimeter(int diameter, int height)
{
return 2 * (diameter + height);
}
int main()
{
int diameter = 5;
int height = 10;
cout << "Perimeter = ";
cout<< perimeter(diameter, height);
cout<<" units\n";
return 0;
}
|
Java
import java.io.*;
class GFG {
static int perimeter(int diameter, int height)
{
return 2 * (diameter + height);
}
public static void main(String[] args)
{
int diameter = 5;
int height = 10;
System.out.println("Perimeter = " +
perimeter(diameter, height)
+ " units\n");
}
}
|
Python
def perimeter( diameter, height ) :
return 2 * ( diameter + height )
diameter = 5 ;
height = 10 ;
print ("Perimeter = ",
perimeter(diameter, height))
|
C#
using System;
class GFG {
static int perimeter(int diameter, int height)
{
return 2 * (diameter + height);
}
public static void Main(String[] args)
{
int diameter = 5;
int height = 10;
Console.Write("Perimeter = " +
perimeter(diameter, height)
+ " units\n");
}
}
|
PHP
<?php
function perimeter($diameter, $height)
{
return 2 * ($diameter + $height);
}
$diameter = 5;
$height = 10;
echo("Perimeter = ");
echo(perimeter($diameter, $height));
echo(" units");
?>
|
Javascript
<script>
function perimeter(diameter, height)
{
return 2 * (diameter + height);
}
let diameter = 5;
let height = 10;
document.write("Perimeter = " +
perimeter(diameter, height)
+ " units\n");
</script>
|
Output :
Perimeter = 30 units
Time Complexity: O(1)
Auxiliary Space: O(1)
Please Login to comment...