- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Haskell Program to calculate the volume and area of Cone

This tutorial will help us in calculating the volume and area of the Cone. The volume of a cone is a measure of the amount of space inside the cone. And area involves the surface area of the cone that is obtained from the lateral area of a cone. The formula for the volume of a cone is V = (1/3) * π * r^2 * h, where r is the radius of the base of the cone, h is the height of the cone, and π is approximately equal to 3.14.

And the formula for the surface area of a cone is A = π * r * s, where r is the radius of the base of the cone and s is the slant height of the cone.

## Algorithm

**Step 1**− The variables named, “radius” and “height” is being initialized. It will contain the radius and height of the cone whose surface area and volume is to be computed.**Step 2**− The volume and area functions are defined on the basis of simple mathematical formula as volume = (pi * radius^2 * height) / 3 ; lateralArea = pi * radius * sqrt(radius^2 + height^2) and surfaceArea = lateralArea + pi * radius^2 respectively.**Step 3**− Program execution will be started from main function. The main() function has whole control of the program. It is written as main = do. The main function takes input from the user for the radius and height of the cone and then uses the above functions to calculate the volume and surface area**Step 4**− The final resultant volume and surface area value is displayed by using ‘putStrLn’ statement and show function once the volume and area functions are called.

## Using User-defined Function

In this example, we use the value of pi and the square root function. The radius and height of the cone are defined as variables at the beginning of the program. We then use these variables to calculate the volume, lateral surface area, and total surface area of the cone using the appropriate formulas. Finally, we use the putStrLn function to print the results to the console.

### Example

radius = 5 height = 10 volume = (pi * radius^2 * height) / 3 lateralArea = pi * radius * sqrt(radius^2 + height^2) surfaceArea = lateralArea + pi * radius^2 main = do putStrLn ("Volume: " ++ show volume) putStrLn ("Surface Area: " ++ show surfaceArea)

### Output

Volume: 261.79938779914943 Surface Area: 254.160184615763

## Using Cone Data Type

This approach defines a Cone data type, which is a record with two fields: radius and height. We then define three functions coneVolume, coneLateralArea and coneSurfaceArea that take a Cone as a parameter and return the respective volume and area. In main function, we create a Cone with radius and height value and then use the defined functions to calculate the volume and surface area and print it to the console.

### Example

data Cone = Cone { radius :: Double, height :: Double } coneVolume :: Cone -> Double coneVolume (Cone r h) = (pi * r^2 * h) / 3 coneLateralArea :: Cone -> Double coneLateralArea (Cone r h) = pi * r * sqrt (r^2 + h^2) coneSurfaceArea :: Cone -> Double coneSurfaceArea c = coneLateralArea c + pi * (radius c)^2 cone = Cone 5 10 main = do putStrLn ("Volume: " ++ show (coneVolume cone)) putStrLn ("Surface Area: " ++ show (coneSurfaceArea cone))

### Output

Volume: 261.79938779914943 Surface Area: 254.160184615763

## Conclusion

There are different ways to calculate the volume, lateral area and surface area of a cone, but the mathematical formula to compute the volume and area of the cone will always remains the same. In Haskell, the volume and the area of a cone can be calculated by using user-defined function or by defining Cone Data Type.

- Related Articles
- Python Program to calculate the volume and area of Cone
- Haskell Program to calculate the volume and area of Sphere
- Golang program to calculate the volume and area of a Cone
- Haskell Program to calculate the volume and area of the Cylinder
- Haskell Program to calculate the volume, diagonal, and area of Cuboids
- Haskell Program to calculate the volume of Cube
- Haskell Program to Find the Surface area and Volume of Cuboid
- Haskell Program to calculate the area of Cube
- Swift Program to calculate the volume and area of Sphere
- C++ Program to calculate the volume and area of Sphere
- Python Program to calculate the volume and area of Sphere
- Haskell Program to calculate the area of the rhombus
- Program to calculate area and volume of a Tetrahedron
- Swift Program to calculate the volume and area of the Cylinder
- Python Program to calculate the volume and area of the Cylinder