Find the perimeter of a cylinder in C++

C++Server Side ProgrammingProgramming

Suppose we have the diameter and the height of the cylinder, we have to find the perimeter of the cylinder. As the perimeter is the outline of two dimensional object, then we cannot find the perimeter of one three dimensional object directly. We can make a cross section of the cylinder, and convert it as rectangle, then find the perimeter. The two sides of the rectangular cross section are the diameter, and the height. So perimeter is −

p=(2*d)+(2*h)

Example

#include<iostream>
using namespace std;
int getCylinderPerimeter(int d, int h) {
   return (2*d) + (2*h);
}
int main() {
   int diameter = 5, height = 10;
   cout << "Perimeter: " << getCylinderPerimeter(diameter, height) << " units";
}

Output

Perimeter: 30 units
raja
Published on 04-Nov-2019 08:07:19
Advertisements