ADVERTISEMENT
ADVERTISEMENT

C program to find the Surface Area and Volume of the Cylinder

Here, we are going to learn how to find the Surface Area and Volume of the Cylinder using C program?
Submitted by Nidhi, on August 06, 2021

Problem Solution:

Read the radius and height of the cylinder from the user, and calculate the volume and surface area of the cylinder.

Cylinder volume formula: πr2h

Cylinder surface area formula: 2πrh+2πr2

Where, r is the radios and h is the height.

Program:

The source code to find the Surface Area and Volume of the cylinder is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.

// C program to find the surface Area and volume
// of the cylinder

#include <stdio.h>

float calcuateVolumeOfCylinder(float radius, float height)
{
    float result = 0.0F;

    result = 3.14F * radius * radius * height;

    return result;
}

float calcuateAreaOfCylinder(float radius, float height)
{
    float result = 0.0F;

    result = 2 * 3.14F * radius * (radius + height);

    return result;
}

int main()
{
    float radius = 0;
    float height = 0;
    float volume = 0;
    float area = 0;

    printf("Enter the radius: ");
    scanf("%f", &radius);

    printf("Enter the height: ");
    scanf("%f", &height);

    volume = calcuateVolumeOfCylinder(radius, height);
    area = calcuateAreaOfCylinder(radius, height);

    printf("Volume of Cylinder is: %f\n", volume);
    printf("Surface area of Cylinder is: %f\n", area);

    return 0;
}

Output:

RUN 1:
Enter the radius: 1
Enter the height: 2
Volume of Cylinder is: 6.280000
Surface area of Cylinder is: 18.840000

RUN 2:
Enter the radius: 2.3
Enter the height: 5.6
Volume of Cylinder is: 93.019356
Surface area of Cylinder is: 114.107597

RUN 3:
Enter the radius: 12.23
Enter the height: 10
Volume of Cylinder is: 4696.588867
Surface area of Cylinder is: 1707.361694

Explanation:

In the above program, we created three functions calcuateVolumeOfCylinder(), calcuateAreaOfCylinder(), and main(). The calcuateVolumeOfCylinder() function is used to calculate the volume of Cylinder based on given radius and hight. The calcuateAreaOfCylinder () function is used to calculate the surface area of Cylinder.

In the main() function, we read the value of the side of Cube from the user. Then we called the calcuateVolumeOfCylinder(), calcuateAreaOfCylinder() functions to calculate the volume and surface area of the Cylinder. After that, we printed the result on the console screen.

C Basic Programs »


ADVERTISEMENT




ADVERTISEMENT



Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.