Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now