C Program to Find Volume of Cylinder

In this post, we will learn how to find the volume of a cylinder using C Programming language.

The Volume of a cylinder is the density of the cylinder which signifies the amount of material it can carry or how much amount of any material can be immersed in it.

  • Volume of Cylinder = πr2h, where r is the radius of the base and h is height of the cylinder.

We will be using this formula in our program to compute the volume of a cylinder.

So, without further ado, let’s begin this tutorial.

C Program to Find Volume of Cylinder

// C Program to Find Volume of Cylinder
#include <stdio.h>
int main(){
    int height, radius;
    float pi, volume;
    
    // Asking for input
    printf("Enter the height of the cylinder: ");
    scanf("%d", &height);
    printf("Enter the radius of the cylinder: ");
    scanf("%d", &radius);
    
    pi = 3.14;
    
    // Calculating volume
    volume = pi * (radius * radius) * height;
    
    // Displaying output
    printf("Volume of Cylinder: %.2f", volume);
    return 0;
}

Output

Enter the height of the cylinder: 12
Enter the radius of the cylinder: 7
Volume of Cylinder: 1846.32

How Does This Program Work ?

    int height, radius;
    float pi, volume;

In this program, we have declared two int data type variables and two float data type variables.

    // Asking for input
    printf("Enter the height of the cylinder: ");
    scanf("%d", &height);
    printf("Enter the radius of the cylinder: ");
    scanf("%d", &radius);

Then, the user is asked to enter the radius and height of the cylinder.

    // Calculating volume
    volume = pi * (radius * radius) * height;

Volume of the cylinder is calculated using the formula πr2h.

    // Displaying output
    printf("Volume of Cylinder: %.2f", volume);

Finally, the volume of the cylinder is printed as output using printf() function.

Conclusion

I hope after going through this post, you understand how to find the volume of a cylinder using C Programming language.

If you have any doubt regarding the program, feel free to contact us in the comment section. We will be delighted to help you.

Also Read:

2 thoughts on “C Program to Find Volume of Cylinder”

Leave a Comment

Your email address will not be published. Required fields are marked *