C++ Program to Find Volume of Cone

Howdy readers, today you will learn how to write a program to find the volume of a cone using the C++ Programming language.

C++ Program to Find Volume of Cone

The volume of a cone is one-third of the product area of circular base and height.

  • Volume of Cone = (1/3)πr2h, where ‘h’ is the height of the cone and ‘r’ is the radius of the base.

The below program takes the radius of the base and height of the cone as input and then finds the volume using the above formula.

So, without any delay, let’s begin this tutorial. 

C++ Program to Find Volume of Cone

C++  Program

// C++ Program to Find Volume of Cone
#include <iostream>
using namespace std;

int main(){
    float radius, height, vol;
    
    // Taking input from the user
    cout << "Enter the radius of the cone: ";
    cin >> radius;
    cout << "Enter the height of the cone: ";
    cin >> height;
    
    // Calculating volume
    vol = (1.0/3.0) * (3.14) * radius * radius * height;
    
    // Displaying result
    cout << "The Volume of the cone is: " << vol << endl;
    
    return 0;
}

Output

Enter the radius of the cone: 5
Enter the height of the cone: 8
The volume of the cone is: 209.333
C++ Program to Find Volume of Cone

Explanation

    float radius, height, vol;

In the above program, we have declared three float data type variables named radius, height, and vol.

    // Taking input from the user
    cout << "Enter the radius of the cone: ";
    cin >> radius;
    cout << "Enter the height of the cone: ";
    cin >> height;

This program prompts the user to enter the radius and height of the cone. These values get stored in the radius and height named variables.

    // Calculating volume
    vol = (1.0/3.0) * (3.14) * radius * radius * height;

The volume of cone is computed using the formula:

Volume of Cone = (1/3)πr2h, where ‘h’ is the height of the cone and ‘r’ is the radius of the base.

    // Displaying result
    cout << "Volume of the cone is: " << vol << endl;

After that, the volume obtained is printed on the screen using the cout function.

Conclusion

I hope after reading this post, you understand how to write a program to find the volume of a cone using the C++ Programming language.

If you have any queries regarding the tutorial, then let us know in the comment section. We will be pleased to solve all of your queries.

Leave a Comment