Program to Calculate the surface area and volume of a Cylinder

Problem statement:-  Program to Calculate the surface area and volume of a Cylinder.

Formula:

Surface Area Of Cylinder(A):  

A
=
2
π
r
h
+
2
π

Volume of Cylinder(V)

V
=
π
h

where r=Radius of the Cylinder
           h=Height of the Cylinder

Data requirement:-

   Input Data:- r,h

  Output Data:- surface_area, volume
   
  Additional Data:-PI

Program in C

Here is the source code of the C Program to Calculate the surface area and volume of a Cylinder.

Code:

#include<stdio.h>
#include<math.h>
#define PI 3.14
int main()
{
    printf("Enter the radius of the cylinder:");
    int r;
    scanf("%d",&r);
    printf("Enter the height of the cylinder:");
    int h;
    scanf("%d",&h);
    double surface_area=(2*PI*r*h)+(2*PI*pow(r,2));
    double volume=PI*pow(r,2)*h;
    printf("Surface Area of the cylinder = %0.2lf\n",surface_area);
    printf("Volume of the cylinder = %0.2lf",volume);
}

Input/Output:
Enter the radius of the cylinder:7
Enter the height of the cylinder:4
Surface Area of the cylinder = 483.56
Volume of the cylinder = 615.44

Program in C++

Here is the source code of the C++ Program to Calculate the surface area and volume of a Cylinder.

Code:

#include<iostream>
#include<cmath>
#define PI 3.14
using namespace std;
int main()
{
    cout<<"Enter the radius of the cylinder:";
    int r;
    cin>>r;
    cout<<"Enter the height of the cylinder:";
    int h;
    cin>>h;
    double surface_area=(2*PI*r*h)+(2*PI*pow(r,2));
    double volume=PI*pow(r,2)*h;
    cout<<"Surface Area of the cylinder = "<<surface_area;
    cout<<"\nVolume of the cylinder = "<<volume;
}

Input/Output:
Enter the radius of the cylinder:10
Enter the height of the cylinder:6
Surface Area of the cylinder = 1004.8
Volume of the cylinder = 1884

Program in Java
  
Here is the source code of the Java Program to Calculate the surface area and volume of a Cylinder.

Code:

import java.util.Scanner;
public class SurfaceAreaAndVolumeOfCylinder {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
double PI=3.14;
System.out.println("Enter the radius of the cylinder:");
    int r=cs.nextInt();
    System.out.println("Enter the height of the cylinder:");
    int h=cs.nextInt();
    double surface_area=(2*PI*r*h)+(2*PI*Math.pow(r,2));
    double volume=PI*Math.pow(r,2)*h;
    System.out.println("Surface Area of the cylinder = "+surface_area);
    System.out.println("Volume of the cylinder = "+volume);
     cs.close();
}
}

Input/Output:
Enter the radius of the cylinder:
14
Enter the height of the cylinder:
10
Surface Area of the cylinder = 2110.08
Volume of the cylinder = 6154.400000000001



Program in Python
  
Here is the source code of the Python Program to Calculate the surface area and volume of a Cylinder.

Code:

import math
PI=3.14
r=int(input("Enter the radius of the cylinder:"))
h=int(input("Enter the height of the cylinder:"))
surface_area=(2*PI*r*h)+(2*PI*math.pow(r,2))
volume=PI*math.pow(r,2)*h
print("Surface Area of the cylinder = ",surface_area)

print("Volume of the cylinder = ",volume)

Input/Output:

Post a Comment

0 Comments