The Program in C++ to Calculate the Volume of a Cylinder is given below:
#iclude <iostream>
using namespace std;
int main()
{
int rad1,hgt;
float volcy;
cout << "\n\n Hello Codeauri Family, You ca Calculate the volume of a cylinder here :\n";
cout << "-----------------------------------------\n";
cout<<" Please give the radius of the cylinder here : ";
cin>>rad1;
cout<<" and height of the cylinder as well : ";
cin>>hgt;
volcy=(3.14*rad1*rad1*hgt);
cout<<" Wow,the volume of a cylinder is : "<< volcy << endl;
cout << endl;
return 0;
}
Output:
Hello Codeauri Family, You ca Calculate the volume of a cylinder here :
Please give the radius of the cylinder here : 8
and height of the cylinder as well : 8
Wow,the volume of a cylinder is : 1607.68
Pro-Tips💡
This code is a simple C++ program that calculates the volume of a cylinder given its radius and height.
The program prompts the user to input the values for the radius and height of the cylinder,
then uses the formula for the volume of a cylinder, which is pi * r^2 * h to calculate the volume, and displays the result on the screen.
It starts with #include <iostream>
which allows the program to perform standard input/output operations.
The using namespace std;
allows the program to use the names of functions and objects from the standard C++ library without having to qualify them with the std:: prefix.
The main()
function is where the program execution starts, it declares the necessary variables, prompts the user for input, performs the calculation
and displays the result and the program ends with return 0
indicating successful completion.
Learn C-Sharp ↗
C-sharp covers every topic to learn about C-Sharp thoroughly.
Learn C Programming ↗
C-Programming covers every topic to learn about C-Sharp thoroughly.
Learn C++ Programming↗
C++ covers every topic to learn about C-Sharp thoroughly.