Slider

C++ Program to Find Volume of a Cube.

Here in this post, we will find the volume of a cube with the help of C++ programming. all sides are of equal length so the volume of our cube will be

A Cube is a geometrical three-dimensional shape formed by six equal square faces. It contains a total of 8 vertices and 12 similar size edges. If we consider the length of any one edge of the cube as a unit then the area of each face of the cube will be a^2. A Cube is a 3D object with length, breadth, and height the volume of a cube will be equal to length x breadth x height and as in our case, all sides are of equal length so the volume of our cube will be a^3.

Here in this post, we will find the volume of a cube with the help of C++ programming. 

C++ Example Code:

//C++ Code Implementation for Volume of Cube
#include<iostream>
using namespace std;

int main(){
    int a, volume;

    cout<<"Calculate the volume of the Cube."<<endl;
    cout<<"Enter the length of the side of Cube: ";
    cin>>a;

    volume = a * a * a;
    cout<<"The Volume of Cube: "<<volume<<endl;

    return 0;
}
Output:
Calculate the volume of the Cube.
Enter the length of the side of Cube: 6
The volume of Cube: 216

In the above code, we have used integer data type to calculate the volume of the cube but if you are dealing with decimal values then it is recommended to use float data type to calculate as it has the capability to represent decimal values.

Next:

0

No comments

Post a Comment

both, mystorymag

DON'T MISS

Tech News
© all rights reserved
made with by AlgoLesson
Table of Contents