C Program to Calculate Volume of Sphere

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

The volume of a sphere is the amount of air that a sphere can hold inside it. The formula of calculating the volume of of a sphere with radius ‘r’ is given by the formula:

  • Volume of Sphere = (4/3)πr3

This program will use the above formula to calculate the volume of a sphere.

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

Contents

C Program to Calculate Volume of Sphere

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

Output

Enter the radius of the sphere: 7
Volume of Sphere: 1436.03

How Does This Program Work ?

    int radius;
    float volume;

In this program, we have declared one int data type variable and one float data type variable.

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

Then, the user is asked to enter the radius of the sphere.

    // Calculating volume of sphere
    volume = (4.0 / 3.0) * 3.14 * radius * radius * radius;

We calculate the volume of the sphere using the formula,  V = (4/3)πr3

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

Finally, the volume of the sphere is printed on the screen using printf() function.

Conclusion

I hope after going through this post, you understand how to calculate the volume of a sphere 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:

Leave a Comment

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