Given the values for radius and height of a Cylinder, write a C program to calculate Surface Area of the Cylinder.
Page Contents
Surface_Area = (2 * PI * radius * height) + (2 * PI * radius * radius);
where PI is approximately equal to 3.14
Related Read:
Basic Arithmetic Operations In C
Area of Rectangle: C Program
Calculate Area of a Circle without using math.h library: C
C Program To Calculate Circumference of Circle
A solid Cylinder has 2 circles. One at the top and one at the bottom. Area of a Circle is PI * radius2. Since there are 2 Circles in the Cylinder, we multiply it by 2.
i.e., 2 (PI * radius2)
Next lets cut the cylinder at one end and open it. It forms a rectangle. Now height of the rectangle and height of the Cylinder are same. Width of the rectangle is equal to circumference of the circle, since top and bottom of the Cylinder are circles.
So, area of rectangle = (2 * PI * radius) * height
Therefore, Surface Area of Cylinder is:
SA = ( (2 * PI * radius) * height ) + ( 2 (PI * radius2) );
User Input:
Enter Radius and Height of the Cylinder
2
5
Output:
Surface Area of Cylinder is 87.920006
Video Tutorial: C Program To Calculate Surface Area of Cylinder
#include<stdio.h> int main() { const float PI = 3.14; float r, h, Area; printf("Enter Radius and Height of the Cylinder\n"); scanf("%f%f", &r, &h); Area = (2 * PI * r * h) + (2 * PI * r * r); printf("Surface Area of Cylinder is %f\n", Area); return 0; }
Output 1:
Enter Radius and Height of the Cylinder
5
10
Surface Area of Cylinder is 471.000031
Output 2:
Enter Radius and Height of the Cylinder
2
13
Surface Area of Cylinder is 188.400009
For list of all c programming interviews / viva question and answers visit: C Programming Interview / Viva Q&A List
For full C programming language free video tutorial list visit:C Programming: Beginner To Advance To Expert