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

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

## C++ Basic: Exercise-44 with Solution

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

Visual Presentation:

Sample Solution:

C++ Code :

``````#include <iostream> // Including the input-output stream header file

using namespace std; // Using the standard namespace

int main() // Start of the main function
{
int rad1; // Declaring an integer variable to store the radius of the sphere
float volsp; // Declaring a floating-point variable to store the volume of the sphere

cout << "\n\n Calculate the volume of a sphere :\n"; // Outputting a message indicating the purpose of the program
cout << "---------------------------------------\n"; // Displaying a separator line

cout << " Input the radius of a sphere : "; // Prompting the user to input the radius of the sphere

// Calculating the volume of the sphere using the formula: (4 * π * r^3) / 3

cout << " The volume of a sphere is : " << volsp << endl; // Outputting the calculated volume of the sphere

cout << endl; // Displaying an empty line for better readability
return 0; // Return statement indicating successful completion of the program
}
``````

Sample Output:

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

Flowchart:

C++ Code Editor:

What is the difficulty level of this exercise?

﻿