C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

C Program: Volume of a Sphere

Introduction (Sphere Volume)

A sphere is a perfectly round 3D solid object where every point on its surface is equidistant from the center.
Examples in real life include balls, globes, and bubbles.

The volume of a sphere represents the total space inside it.
The formula is:

Volume = 3/4 π r3

where

  • r = radius of the sphere
  • π (pi) ≈ 3.14159

 

C Program: Volume of a Sphere

C

#include <stdio.h>

#define PI 3.14159   // Define constant PI

 

int main() {

    float radius, volume;

 

    // Input radius

    printf("Enter the radius of the sphere: ");

    scanf("%f", &radius);

 

    // Calculate volume

    volume = (4.0/3.0) * PI * radius * radius * radius;

 

    // Display result

    printf("Volume of Sphere = %.2f\n", volume);

 

    return 0;

}

Output

 
OUTPUT 1 :
Enter the radius of the sphere: 7
Volume of Sphere = 1436.76


OUTPUT 2 :
Enter the radius of the sphere: 3.5
Volume of Sphere = 179.59


Explanation

  1. The user enters the radius of the sphere.
  2. Formula used: (4/3) × π × r³.
  3. PI is defined using #define for accuracy.
  4. The program prints the volume rounded to two decimals.