Write a computeSphere() function that returns the volume and surface area. Implement a
main function which reads the radius, calls the above function and prints the result.
#include <iostream>
using namespace std;
const float pi = 3.14159;
// Volume Of Sphere
float volume(float r) {
float vol;
vol = (4.0 / 3.0) * pi * r * r * r;
return vol;
}
// Surface Area of Sphere
float surface_area(float r)
{
float sur_ar;
sur_ar = 4.0 * pi * r * r;
return sur_ar;
}
int main() {
float radius;
float vol, sur_area;
cout<<"Enter Radius: ";
cin>>radius;
cout<<endl;
vol = volume(radius);
sur_area = surface_area(radius);
cout << "Volume Of Sphere: " << vol << endl;
cout << "Surface Area Of Sphere: " << sur_area << endl;
return 0;
}
Comments
Leave a comment