Write a C++ program that inputs radius of sphere from the user. Calculates its volume and surface area using the formula Area = 4 \pi R ^ { 2 } and circumference = 4/ 3 \pi R ^ { 3 } where pi =3.14

 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.

Copyright © 2025 AWS Tutorials | Distributed by Blogger Templates | Designed by OddThemes