In this tutorial you will learn about the C Program to Find Volume and Surface Area of a Cylinder and its application with practical example.
C Program to Find Volume and Surface Area of a Cylinder
In this tutorial, we will learn to create a C program that will Find the Volume and Surface Area of a Cylinder in C programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- Mathematical operations in C programming.
What is a Cylinder?
The cylinder is a 3d shape containing two parallel lines and the circles connected to form a cylindrical shape in geometry. The distance between the two circular bases is called the height of the cylinder.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declaring the required variables for the program. 2. Taking the input radius and the height of the cylinder from the user. 3. <strong>C</strong><strong>alculating the Surface Area and volume of a Cylinder </strong>using the code. 4. Printing the surface area of the <strong>Cylinder</strong>. 5. End the program. |
Program description:-
In today’s tutorial, we will create a program, that will calculate the Volume and Surface Area of a Cylinder using C programming. First, take the height and the radius of the Cylinder as input from the user. Then we will find the surface area and the volume of a Cylinder using mathematical expressions and calculations. At last, we will print the Volume and Surface Area of a Cylinder.
Program Code:-
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 28 29 30 |
/* C Program to find Volume and Surface Area of a Cylinder */ //including the header files #include<stdio.h> #include<math.h> int main() { //declaring the required variables for the program float rd, ht; //rd = it will hold the integer value for the input radius //ht = it will hold the integer value for the input height float sa,vol; //vol = it will hold the volume of the cylinder. //Taking the input radius and the height of the cylinder printf("\n Please Enter the radius and height of a cylinder \n"); scanf("%f %f", &rd, &ht);//scanning the input radius and the height //Calculating the surface area of the cylinder sa = 2 * M_PI * rd * (rd + ht); //Calculating the volume of the cylinder vol = M_PI * rd * rd * ht; //Printing the Surface Area of a cylinder printf("\n Surface Area of a cylinder = %.2f", sa); //Printing the Volume of a cylinder printf("\n Volume of a Cylinder = %.2f", vol); return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- rd = it will hold the integer value for the input radius of the cylinder.
- ht = it will hold the integer value for the input radius of the cylinder.
- sa = it will hold the integer the surface area of the cylinder
- vol = it will hold the value of the volume of the cylinder.
Taking the input length of the side of the cylinder.
Calculating the surface area & volume of the cylinder.
Printing the volume and surface area of the cylinder.