# C Program to Find Volume and Surface Area of a Cube

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

Problem Description

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

Problem Solution

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

Program/Source Code

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);
}```
Program Explanation

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.

Runtime Test Cases
```
\$ 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 Books in C Programming, Data-Structures and Algorithms

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
If you wish to look at other example programs on Mathematical Functions, go to C Programming Examples on Mathematical Functions. If you wish to look at programming examples on all topics, go to C Programming Examples.

If you find any mistake above, kindly email to [email protected]