Program to calculate volume and surface area of cylinder

Description

To calculate volume of a Cylinder use formula
	volume = PI x radius x radius x height

To calculate Surface Area of a Cylinder use formula
	Surface area = 2 x PI x radius x height + 2 x PI x radius x radius
	
	where PI = 3.14285714286

C/C++

/* C Program to calculate volume and surface area of cylinder */
//Save it as VolumeSurfaceAreaCylinder.c

#include<stdio.h>
#define PI 3.14285714286
int main(){

    float radius, height, volume, surfaceArea;

    printf("Enter the Radius of Cylinder : ");
    scanf("%f",&radius);

    printf("Enter the Height of Cylinder : ");
    scanf("%f",&height);

    //The volume of cylinder is calculated using the formula
    //Volume = PI x radius x radius x height
    volume = PI*radius*radius*height;

    printf("The volume of cylinder : %.3f",volume);
    
    /*To find the surface area of a cylinder add the surface area of each end
     plus the surface area of the side. Each end is a circle so the surface
     area of each end is PI x radius x radius, where radius is the radius of the end.
     There are two ends so their combined surface area is 2 x PI x radius x radius.
     The surface area of side is 2 x PI x radius x height */
     surfaceArea = ((2*PI*radius*height) + (2*PI*radius*radius));

     printf("\nThe Surface Area of cylinder : %.3f",surfaceArea);

     return 0;
}
Input:
Enter the Radius of Cylinder : 15
Enter the Height of Cylinder : 17

Output:
The volume of cylinder = 12021.428
nThe Surface Area of cylinder = 3017.1428

Java

/* Java Program to calculate volume and surface area of cylinder */
//Save it as VolumeSurfaceAreaCylinder.java

import java.io.*;
import java.util.Scanner;

public class VolumeSurfaceAreaCylinder {

    public static void main(String[] args) {

            Scanner scanner = new Scanner(System.in);
        
            float radius, height, volume, surfaceArea, PI=(float) 3.14285714286;

        System.out.println("Enter the Radius of Cylinder : ");
        radius = scanner.nextFloat();

        System.out.println("Enter the Height of Cylinder : ");
        height = scanner.nextFloat();

            //The volume of cylinder is calculated using the formula
        //Volume = PI x radius x radius x height
        volume = PI*radius*radius*height;

        System.out.println("The volume of cylinder = "+volume);


        /*To find the surface area of a cylinder add the surface area of each end
         plus the surface area of the side. Each end is a circle so the surface
         area of each end is PI x radius x radius, where radius is the radius of the end.
         There are two ends so their combined surface area is 2 x PI x radius x radius.
         The surface area of side is 2 x PI x radius x height */
         surfaceArea = ((2*PI*radius*height) + (2*PI*radius*radius));

         System.out.println("The Surface Area of cylinder = "+surfaceArea);
    }
}
Input:
Enter the Radius of Cylinder : 
15
Enter the Height of Cylinder : 
17

Output:
The volume of cylinder = 12021.428
The Surface Area of cylinder = 3017.1428

Related Programs

1) Program to calculate area of a circle
2) Program to calculate area of triangle
3) Program to calculate Area Of right angle triangle
4) Program to calculate area of square
5) Program to calculate volume and surface area of cube
6) Program to calculate area of a Rectangle
7) Program to calculate Volume and Surface Area of Sphere
Share Me

Leave a Reply