Given the value for radius of a Sphere, write a C program to calculate volume of the Sphere.
Page Contents
volume = ( 4 * PI * radius3 ) / 3.0;
OR
volume = ( 1.333 * PI * radius3 );
where PI is approximately equal to 3.14;
Related Read:
Basic Arithmetic Operations In C
User Input:
Enter Radius of the Sphere
5
Output:
Volume of Sphere is 523.333374
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
#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