Write a C++ program that reads in the radius of a Sphere, then calculates and prints its volume and surface area.
#include <iostream>
using namespace std;
const float pi = 3.1415;
float volume(float r) {
return (float(4) / float(3)) * pi * r * r * r;
}
float surface_area(float r) {
return 4 * pi * r * r;
}
int main() {
float radius;
float vol, surfaceArea;
cout<<"Enter radius: ";
cin>>radius;
vol = volume(radius);
surfaceArea = surface_area(radius);
cout << "Volume: " << vol << endl;
cout << "Surface: " << surfaceArea << endl;
return 0;
}
Comments
Leave a comment