Sunday, 15 June 2014

C++ program to calculate volume of a cylinder and sphere



Here is a C++ program to calculate volume of a cylinder and sphere


 SOURCE CODE OUTPUT
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
        float svol, cvol, sradius, cradius, height, vsa, sa;
        cout<<"Enter the radius of the sphere:";
        cin>>sradius;
        cout<<"Enter the volume and radius of the cylinder:";
        cin>>cradius>>height;
        svol = (4 * 3.14 * sradius * sradius * sradius) / 3;
        sa = 4 * 3.14 * sradius * sradius;
        cvol = 3.14 * cradius * cradius * height;
        vsa = 2 * 3.14 * cradius * (cradius + height);
        cout<<"Volume of the cylinder: "<<cvol<<endl;
        cout<<"Surface area of cylinder : "<<vsa<<endl;
        cout<<"Volume of the sphere: "<<svol<<endl;
        cout<<"Surface area of sphere: "<<sa<<endl;
        return 0;
}

Any questions regarding to program please write in comments.

No comments:

Post a Comment