C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

C Program: Surface Area of a Cuboid

Introduction

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

The surface area of a cuboid is the total area of all six faces.
The formula is:

Surface Area = 2× ( l×w + l×h + w×h )

where

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

 

C Program: Surface Area of a Cuboid

C

#include <stdio.h>

 

int main() {

    float length, width, height, surface_area;

 

    // 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 surface area

    surface_area = 2 * (length * width + length * height + width * height);

 

    // Display result

    printf("Surface Area of Cuboid = %.2f\n", surface_area);

 

    return 0;

}

Output

 
OUTPUT 1 :
Enter length of the cuboid: 10
Enter width of the cuboid: 5
Enter height of the cuboid: 4
Surface Area of Cuboid = 220.00

OUTPUT 2 :
Enter length of the cuboid: 7.5
Enter width of the cuboid: 3.2
Enter height of the cuboid: 6
Surface Area of Cuboid = 207.60

Explanation

  1. The program asks for length, width, and height of the cuboid.
  2. Formula applied: 2 × (l × w + l × h + w × h).
  3. The result is printed with two decimal places.