C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

C Program: Surface Area of a Cube

Introduction

A cube is a 3D solid object with six equal square faces.
The surface area of a cube represents the total area of all six faces.

The formula is:

Surface Area=6a2

where

    a = length of one side of the cube

 

C Program: Surface Area of a Cube

C

#include <stdio.h>

 

int main() {

    float side, surface_area;

 

    // Input side length

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

    scanf("%f", &side);

 

    // Calculate surface area

    surface_area = 6 * side * side;

 

    // Display result

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

 

    return 0;

}

Output

 
OUTPUT 1 :
Enter the side length of the cube: 5
Surface Area of Cube = 150.00


OUTPUT 2 :
Enter the side length of the cube: 7.2
Surface Area of Cube = 311.04


Explanation

  • User enters the side length of the cube.
  • Formula applied: 6 × a².
  • The program prints the surface area rounded to two decimal places.