C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

C Program: Volume of a Cube

Introduction

A cube is a three-dimensional solid object bounded by six equal square faces.
In geometry and real life, cubes appear in dice, ice cubes, and packaging boxes.

The volume of a cube represents the amount of space enclosed inside it.
It is calculated using the formula:

Volume = a3

where a is the length of one side of the cube.

This program asks the user to enter the side length of the cube, then computes and displays its volume.

C Program: Volume of a Cube

C

#include <stdio.h>

 

int main() {

    float side, volume;

 

    // Input side length of the cube

    printf("Enter the side length of the cube: ");

    scanf("%f", &side);

 

    // Calculate volume

    volume = side * side * side;

 

    // Display result

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

 

    return 0;

}

Output

 
OUTPUT 1 :
Enter the side length of the cube: 5
Volume of Cube = 125.00

OUTPUT 2 :
Enter the side length of the cube: 3.2
Volume of Cube = 32.77


Explanation

  1. Input → The program takes the side length of the cube as input.
  2. Process → It applies the formula side × side × side.
  3. Output → The result is printed with two decimal places.