Tuesday, January 31, 2023

Calculate the volume of a sphere

Write a program in C++ to calculate the volume of a sphere.

The Volume of a Sphere may be calculated in following terms

in terms of radius

V = 4/3πr3

V ≈ 4.1888r3

in terms of surface area

V = A3/2 6π

V ≈ 0.09403A3/2

in terms of circumference

V = C32

V ≈ 0.01689C3

Where

r = radius
V = volume
A = surface area
C = circumference
π = pi = 3.1415926535898
√ = square root



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:    6

The volume of a sphere is :     904.32

 

No comments:

Post a Comment

Popular Posts