C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

C Program: Volume of a Cone

Introduction (Cone Volume)

A cone is a 3D solid shape with a circular base that tapers smoothly to a single point called the apex.
Examples in real life include ice-cream cones, funnels, and traffic cones.

The volume of a cone represents the space enclosed within it.
The formula is:

Volume = 1/3 π r2 h

where

  • r = radius of the circular base
  • h = height of the cone
  • π (pi) ≈ 3.14159

 

C Program: Volume of a Cone

C

#include <stdio.h>

#define PI 3.14159   // Define constant PI

 

int main() {

    float radius, height, volume;

 

    // Input radius and height

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

    scanf("%f", &radius);

 

    printf("Enter the height of the cone: ");

    scanf("%f", &height);

 

    // Calculate volume

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

 

    // Display result

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

 

    return 0;

}

Output

 
OUTPUT 1 :
Enter the radius of the cone: 3
Enter the height of the cone: 7
Volume of Cone = 65.97

OUTPUT 2 :
Enter the radius of the cone: 4.5
Enter the height of the cone: 10
Volume of Cone = 212.06


Explanation

  1. The program takes radius and height as input.
  2. Formula applied: (π × r² × h) ÷ 3.
  3. PI is defined using #define.
  4. The volume is displayed with two decimal places.