C++

Calculate Volume of a Cylinder in C++

A Simple C Program to Calculate Volume of a Cylinder

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include<iostream>
#include<math.h> 
using namespace std;
#define PI 3.14159265 

int main() {

int radius;
     int height;

        float area;
           float volume;

              cout<<"Enter the radius of the circle:\n";
            cin>>radius;
        cout<<("Enter the height of the cylinder:\n");
    cin>>height;

radius=pow(radius,2)*PI;

    volume=radius*height;

        cout<<"The area of the circle = %.3f\n"<< area;/*Truncate the output to 3 decimal places uding %.3f*/
            cout<<"The volume of the cylinder = %.4f\n"<< volume;/*Truncate the output to 4 decimal places uding %.4f*/

             
}

 

Download Link


Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button
Close
Close