Write a complete program that prompts the user for the radius of a sphere, calculates and prins the volume of that sphere. Use a function sphere volume that returs the results of the following expression: (4/3)*π*r3 which is equivalent to (4.0/3.0) *3.14159*pow(radius,3) in C++ code. Sample output Enter the length of the radius of your sphere: 2 volume of sphere with radius 2 is 33.5103
#include <iostream>
#include <cmath>
int main() {
const float PI = 3.14159;
float radius;
std::cout << "Enter the length of the radius of your sphere: ";
std::cin >> radius;
float volume = (4.0 / 3.0) * PI * std::pow(radius, 3);
std::cout << "Volume of sphere with radius " << radius << " is " << volume << '\n';
return 0;
}
Comments
Leave a comment