C++
#include <iostream>
#include <math.h>
using namespace std;
int main() {
// Declare variables
double radius, volume, surface_area;
const double pi = 3.14;
// Get the radius from the user
cout << "Enter the radius of the sphere: ";
cin >> radius;
// Calculate the volume and surface area of the sphere
volume = (4 / 3) * pi * radius * radius * radius;
surface_area = 4 * pi * radius * radius;
// Print the results
cout << "The volume of the sphere is: " << volume << endl;
cout << "The surface area of the sphere is: " << surface_area << endl;
return 0;
}
To run this program, you can save it as a .cpp
file and compile it using a C++ compiler. For example, on Linux or macOS, you can use the following command to compile the program:
g++ -o program program.cpp
Once the program is compiled, you can run it by typing the following command:
./program
For example, if you enter 5 as the radius, the program will print the following output:
Enter the radius of the sphere: 5
The volume of the sphere is: 523.599
The surface area of the sphere is: 314.16
I hope this helps! Let me know if you have any other questions.