In: Computer Science
Write a C++ program to calculate the sphere volume and surface
area. Provided
that the sphere volume = and the sphere surface area = , where r is
the radius.
1. Read r from the user using cin statement.
2. Calculate the volume (Vol) and the surface area (Area) of a
sphere.
3. Print r, Vol, and Area in a suitable messages.
#include<bits/stdc++.h>
using namespace std;
int main()
{
//declare the variable
double r,Area,Vol;
//calculate the pi value
double pi = 2*acos(0.0);
//prompt message for the user
cout<<"Enter the radius : ";
//take input from the user
cin>>r;
//calculate volume of sphere
Vol = 4*pi*pow(r,3)/3;
//surface area of sphere
Area = 4*pi*pow(r,2);
//print the volume
cout<<"The sphere volume = "<<Vol;
//print the surface area
cout<<" and the sphere surface area =
"<<Area;
//print the radius
cout<<", where "<<r<<" is the
radius.";
}
If you have any problem then let me know in comment box and if you like then please rate or give a big thumbs up thank you.