Home »
C solved programs »
C basic programs
C program to calculate the area of Cube
Here, we are going to learn how to calculate the area of Cube using C program?
Submitted by Nidhi, on August 06, 2021
Problem statement
Read the length of the side of Cube from the user, and calculate the area of Cube.
Area of Cube formula: 6 x side2 or 6a2
Where, side (or a) is the length of the side (i.e., edge)
C program to calculate the area of Cube
The source code to calculate the area of Cube is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.
// C program to calculate the area of Cube
#include <stdio.h>
float calcuateAreaOfCube(float side)
{
float result = 0.0F;
result = 6.0 * side * side;
return result;
}
int main()
{
float side = 0;
float area = 0;
printf("Enter the length of side: ");
scanf("%f", &side);
area = calcuateAreaOfCube(side);
printf("Area of Cube is: %f\n", area);
return 0;
}
Output
RUN 1:
Enter the length of side: 2.4
Area of Cube is: 34.560001
RUN 2:
Enter the length of side: 10.23
Area of Cube is: 627.917358
RUN 3:
Enter the length of side: 12.0
Area of Cube is: 864.000000
Explanation
In the above program, we created two functions calcuateAreaOfCube() and main(). The calcuateAreaOfCube() function is used to calculate the area of Cube based on the given side of Cube.
In the main() function, we read the value of the side of Cube from the user. Then we called the calcuateAreaOfCube() function to calculate the area of the Cube.
C Basic Programs »