C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

C Program: Volume of a Cuboid

Introduction

A cuboid is a 3D solid shape with six rectangular faces. Examples in real life include books, boxes, and bricks.

The volume of a cuboid represents the total space it occupies.
The formula is:

Volume = l × w × h

where

  • l = length
  • w = width (breadth)
  • h = height

C Program: Volume of a Cuboid

C

#include <stdio.h>

 

int main() {

    float length, width, height, volume;

 

    // Input dimensions

    printf("Enter length of the cuboid: ");

    scanf("%f", &length);

 

    printf("Enter width of the cuboid: ");

    scanf("%f", &width);

 

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

    scanf("%f", &height);

 

    // Calculate volume

    volume = length * width * height;

 

    // Display result

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

 

    return 0;

}

Output

 
OUTPUT 1 :
Enter length of the cuboid: 10
Enter width of the cuboid: 5
Enter height of the cuboid: 4
Volume of Cuboid = 200.00


OUTPUT 2 :
Enter length of the cuboid: 7.2
Enter width of the cuboid: 3.5
Enter height of the cuboid: 2.5
Volume of Cuboid = 63.00

Explanation

  1. The program asks the user to input length, width, and height.
  2. It applies the formula l × w × h.
  3. The result is displayed with two decimal places.