C Program To Calculate Volume of Sphere


Given the value for radius of a Sphere, write a C program to calculate volume of the Sphere.

Formula To Calculate Volume of Sphere

volume = ( 4 * PI * radius3 ) / 3.0;

OR

volume = ( 1.333 * PI * radius3 );

volume of sphere

where PI is approximately equal to 3.14;

Related Read:
Basic Arithmetic Operations In C

Expected Output for the Input

User Input:
Enter Radius of the Sphere
5

Output:
Volume of Sphere is 523.333374

Logic To Calculate Volume of Sphere

We ask the user to enter value for radius of the Sphere. If user enters 5 inche. Then we use the formula to calculate the Volume of Sphere:

volume = ( 4 * PI * radius3 ) / 3.0;

User input:
radius = 5 inches;

PI value is approximately equal to 3.14;

volume = ( 4 * PI * radius3 ) / 3.0
volume = ( 4 * 3.24 * (5 inches)3) / 3.0
volume = ( ‭12.56‬ * 125 inches3 ) / 3.0
volume = ( ‭12.56‬ * 125 inches3 ) / 3.0
volume = ‭1,570‬ inches3 / 3.0
volume = ‭523.33 inches3

Video Tutorial: C Program To Calculate Volume of Sphere


[youtube https://www.youtube.com/watch?v=rpQzrFSWj6c]

YouTube Link: https://www.youtube.com/watch?v=rpQzrFSWj6c [Watch the Video In Full Screen.]

Source Code: C Program To Calculate Volume of Sphere

#include<stdio.h>

int main()
{
    const float PI = 3.14;
          float r, volume;

    printf("Enter Radius of the Sphere\n");
    scanf("%f", &r);

    volume = ( 4 * PI * r * r * r ) / 3.0;

    printf("Volume of Sphere is %f\n", volume);

    return 0;
}

Output 1:
Enter Radius of the Sphere
3
Volume of Sphere is 113.040001

Output 2:
Enter Radius of the Sphere
14
Volume of Sphere is 11488.213867

For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List

For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert

Leave a Reply

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