A Sphere is a geometrical three-dimensional ball-like structure with no face. It is basically a set of points that are present at an equal distance from a given point in three-dimensional space and this equal distance r is known as the radius of the Sphere.
In this post, we are going to learn how to calculate the volume of a sphere and how to implement the same in C++ programming.
The volume of any object is basically the amount of space that the object takes in three-dimensional space. The simple formula to calculate the volume of a sphere is shown below.
C++ Example Code:
//C++ Code Implementation for Volume of Sphere #include<iostream> using namespace std; int main(){ int r; float volume; cout<<"Calculate the volume of the Sphere."<<endl; cout<<"Enter the radius of Sphere: "; cin>>r; volume = (4/3) * 3.14 * r * r * r; cout<<"The Volume of Sphere: "<<volume<<endl; return 0; }
Calculate the volume of the Sphere.
Enter the radius of Sphere: 4.5
The volume of Sphere: 200.96
No comments:
Post a Comment