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
float side, surfacearea, volume;
printf("Enter the length of a side \n");
surfacearea = 6.0 * side * side;
volume = pow(side, 3);
printf("Surface area = %6.2f and Volume = %6.2f \n", surfacearea,
$ cc pgm45.c -lm $ a.out Enter the length of a side 34 Surface area = 6936.00 and Volume = 39304.00
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.
Sanfoundry Global Education & Learning Series – 1000 C Programs.