C Program To Calculate Volume of Cone


Given the values for radius and height of a Cone, write a C program to calculate volume of the Cone.

Formula To Calculate Volume of Cone

volume = ( Base_Area x height ) / 3.0;

Base of the Cone is a Circle. Area of Circle is PI x Radius2

So lets replace Base_Area with Area of Circle: PI x Radius2.

Therefore, volume = ( (PI x Radius2) x height ) / 3.0;

volume of Cone

where PI is approximately equal to 3.14159265359;

Related Read:
Basic Arithmetic Operations In C

Expected Output for the Input

User Input:
Enter radius and height of the cone
2
5

Output:
Volume of Cone is 20.933334

Logic To Calculate Volume of Cone

We ask the user to enter values for radius and height of the Cone. If user enters 2m and 5m. Then we use the formula to calculate the Volume of Cone:

volume = (PI x Radius2 x height) / 3.0;

User input:
radius = 2m;
height = 5m;

PI value is 3.14159265359;

volume = ( PI x Radius2 x height ) / 3.0;
volume = ( 3.14 x (2m)2 x (5m) ) / 3.0;
volume = ( 3.14 x 4(m)2 x 5(m) ) / 3.0;
volume = ( 3.14 x 20 m3 ) / 3.0;
volume = ( ‭62.8 m3 ) / 3.0;
volume = 20.93‬ m3;

So volume of Cone is 20.93 cubic meter.

Video Tutorial: C Program To Calculate Volume of Cone


[youtube https://www.youtube.com/watch?v=yjyQadX03A8]

YouTube Link: https://www.youtube.com/watch?v=yjyQadX03A8 [Watch the Video In Full Screen.]

Source Code: C Program To Calculate Volume of Cone

#include<stdio.h>

int main()
{
    const float PI = 3.14;
          float r, h, volume;

    printf("Enter radius and height of the cone\n");
    scanf("%f%f", &r, &h);

    volume = (PI * r * r * h) / 3.0;

    printf("Volume of Cone is %f\n", volume);

    return 0;
}

Output 1:
Enter radius and height of the cone
8
18
Volume of Cone is 1205.760010

Output 2:
Enter radius and height of the cone
5
14
Volume of Cone is 366.333344

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

Leave a Reply

Your email address will not be published. Required fields are marked *