82.1k views
2 votes
Given sphere_radius and pi, compute the volume of a sphere and assign sphere_volume with the volume. Volume of sphere = (4.0 / 3.0) π r3

Sample output with input: 1.0

User Angelmedia
by
3.5k points

2 Answers

1 vote

Answer:

Following are the program in C++ language

#include <iostream>// header file

using namespace std; // namespace

int main() // main method

{

float sphere_radius,sphere_volume ; // variable declaration

float pi=3.14; // variable initialization

cout<<" Enter the radius:";

cin>>sphere_radius; // Read the value by user

sphere_volume=(4.0 / 3.0) * pi* sphere_radius*sphere_radius*sphere_radius; // calculated the volume

cout<<"The volume is:"<<sphere_volume; // display volume

return 0;

}

Output:

Enter the radius:

1.00

The volume is: 4.18667

Step-by-step explanation:

Following are the description of program

  • Declared a variable sphere_radius,sphere_volume as "float" type .
  • Declared a variable pi and initialized with "3.14".
  • Read the value of radius by user in the "sphere_radius".
  • Now calculated the volume by using given formula .
  • Finally print the "sphere_volume".
User Nico Mee
by
3.4k points
3 votes

To compute sphere volume we would have the following; sphere_volume =(((4.0/3.0) * 3.14159 * 1 ** 3

print(sphere_volume)

How to compute the volume of the sphere

This variable sphere_volume, will store the calculated volume of the sphere. The mathematical expression calculates the volume of the sphere.

4.0/3.0 represents the constant value 4/3, which is a factor in the formula for the volume of a sphere and 3.1415 is an approximation of the mathematical constant pi (π), used for calculating the volume of a sphere.

1 ** 3 raises 1 to the power of 3, which is the radius of the sphere cubed.

User Jayy
by
4.1k points