Read the length of the side of the Cube from the user, and calculate the volume of the Cube.
Volume of Cube formula: side3 or a3
Where, side (or a) is the length of the side (i.e., edge)
Program:
The source code to calculate the volume 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 volume of Cube
#include <stdio.h>
float calcuateVolumeOfCube(float side)
{
float result = 0.0F;
result = side * side * side;
return result;
}
int main()
{
float side = 0;
float volume = 0;
printf("Enter the length of side: ");
scanf("%f", &side);
volume = calcuateVolumeOfCube(side);
printf("Volume of Cube is: %f\n", volume);
return 0;
}
Output:
RUN 1:
Enter the length of side: 2.4
Volume of Cube is: 13.824001
RUN 2:
Enter the length of side: 10.23
Volume of Cube is: 1070.598999
RUN 3:
Enter the length of side: 12.0
Volume of Cube is: 1728.000000
Explanation:
In the above program, we created two functions calcuateVolumeOfCube() and main(). The calcuateVolumeOfCube() function is used to calculate the volume 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 calcuateVolumeOfCube() function to calculate the volume of the Cube. After that, we printed the result on the console screen.
Read the length of the side of the Cube from the user, and calculate the volume of the Cube.
Volume of Cube formula: side3 or a3
Where, side (or a) is the length of the side (i.e., edge)
Program:
The source code to calculate the volume of Cube is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.
Output:
Explanation:
In the above program, we created two functions calcuateVolumeOfCube() and main(). The calcuateVolumeOfCube() function is used to calculate the volume 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 calcuateVolumeOfCube() function to calculate the volume of the Cube. After that, we printed the result on the console screen.