×

C Programs

C Basic & Conditional Programs

C Looping Programs

C String Programs

C Miscellaneous Programs

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 statement

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.

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

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 »

Related Programs

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.