How to Find the Volume of Cube
In this program, we are going to discuss how to calculate the volume of a cube, so let’s start!
C Program To Calculate Volume Of Cube
The volume of Cube Formula
Before starting the program, we have to know about the formula of the volume of a cube. So the formula for the volume of a cube is:
Volume of cube = side * side * side
So now let’s see how we can implement these formulas in our program. we can simply calculate the volume of a cube by using this formula.
#include<stdio.h>
int main()
{
float side ;
float volume;
printf(“Enter the side of cube:”);
scanf(“%f”,&side);
volume = side * side * side;
printf(“The Volume of the cube is %f”, volume);
return 0;
}
Output
Enter the side of cube: 2.2
The volume of the cube is 10.648001
Step 1: take two float data type variables. One for user input and another to calculate the volume.
Step 2: apply the formula to calculate the volume of a cube that is :
Volume = side * side * side.
Step 3: To print the answer simply use printf statement.
Step 4: Press F9 to run this program.
First, we get a side of the cube from the user by using the side variable, after that, we use scanf to get user input then we simply apply the formula and print the volume of our cube.
So in this way, we can simply find the volume of a cube. I hope this program is helpful for you.