This is a C Program to compute the surface area & volume of a cube.

This C Program computes the surface area & volume of a cube.

The formula used to find the surface area and volume of the cube is surface_area = 6 * (a * a) and volume = a * a * a.

Here is source code of the C program to compute the surface area & volume of a cube. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

/* * C program to compute the surface area and volume of a cube */ #include <stdio.h> #include <math.h> void main() { float side, surfacearea, volume; printf("Enter the length of a side \n"); scanf("%f", &side); surfacearea = 6.0 * side * side; volume = pow(side, 3); printf("Surface area = %6.2f and Volume = %6.2f \n", surfacearea, volume); }

In this C program, library function is used in header file to compute mathematical functions. We are entering the length of a side using side variable. Now to find the surface area of a cube the formula, surface area = 6 *(side * side) is used. Then, to find the volume of a cube the formula, volume = pow(side,3) is used. Here, the program uses power function defined in math library. Finally, the surface area and volume will be displayed in the standard output.

$ cc pgm45.c -lm $ a.out Enter the length of a side 34 Surface area = 6936.00 and Volume = 39304.00

**Sanfoundry Global Education & Learning Series – 1000 C Programs.**

Here’s the list of Best Reference Books in C Programming, Data-Structures and Algorithms