Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C++ Exercises: Get the volume of a sphere with radius 6

C++ Basic: Exercise-44 with Solution

Write a language program to get the volume of a sphere with radius 6.

Pictorial Presentation:

C++ Exercises: Get the volume of a sphere with radius 6

Sample Solution:

C++ Code :

#include <iostream>
using namespace std;

    int main()
    {
    	int rad1;
    	float volsp;
		cout << "\n\n Calculate the volume of a sphere :\n";
		cout << "---------------------------------------\n";		
        cout<<" Input the radius of a sphere : ";
    	cin>>rad1;
    	volsp=(4*3.14*rad1*rad1*rad1)/3;
        cout<<" The volume of a sphere is : "<< volsp << endl;
        cout << endl;
        return 0;
    }

Sample Output:

Calculate the volume of a sphere :                                    
---------------------------------------                                
 Input the radius of a sphere : 5                                      
 The volume of a sphere is : 523.333

Flowchart:

Flowchart: Get the volume of a sphere with radius 6

C++ Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a language program which accepts the radius of a circle from the user and compute the area and circumference.
Next: Write a program in C++ to calculate the volume of a Cone.

What is the difficulty level of this exercise?