- 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 Find the Area of a Trapezium

This tutorial discusses writing a program to print the area of a trapezium in the Haskell programming language.

A trapezium is a quadrilateral with one opposite side parallel.

The above figure is a trapezium. The length of one of the parallel sides is denoted by a and the other side is denoted by b. The height of the trapezium is denoted by h.

The area of a trapezium is defined as (a+b)/(2*h), where a and b are the lengths of the parallel sides and h is the height or distance between the parallel sides.

In this tutorial, we see two ways to implement a program to find the area of the trapezium.

- Program to find the area of the trapezium in the main function.
- Program to find the area of the trapezium using a custom function.

## Algorithm Steps

- Take input or initialize the variables.
- Implement the program logic to compute the area of the trapezium.
- Print or display the area.

## Example 1

Program to find the area of the trapezium in the main function

main :: IO() main = do -- declaring and initializing variables for sides and height let a = 5 let b = 6 let h = 8 -- computing the area let area = 0.5*(a+b)*h -- printing or displaying the area print ("The area of the trapezium with parallel sides "++ show a ++ "," ++ show b ++ " and height " ++ show h ++ " is:") print (area)

## Output

"The area of the trapezium with parallel sides 5.0,6.0 and height 8.0 is:" 44.0

In the above program, we declared and initialized variables for sides and height as a, b, and h respectively with values 5, 6, and 8. We computed the area of the trapezium using the appropriate formula using the variables and loaded it into a variable area. Finally, printed the area using the print function.

**Note** − The function show takes the argument a number and returns the parsed string of a number. “++” is an operator to concatenate strings in Haskell.

## Example 2

Program to find the area of the trapezium using a custom function

-- function declaration area :: Float->Float->Float->Float -- function definition area a b h = 0.5*(a+b)*h main :: IO() main = do -- declaring and initializing variables for sides and height let a = 5 let b = 6 let h = 8 -- computing the area let d = area a b h -- printing or displaying the area print ("The area of the trapezium with parallel sides "++ show a ++ "," ++ show b ++ " and height " ++ show h ++ " is:") print (d)

## Output

"The area of the trapezium with parallel sides 5.0,6.0 and height 8.0 is:" 44.0

In the above program, we declared a function area as such it takes three float arguments and returns a float. In its function definition, three arguments are accepted a, b, and c. In this area of the trapezium is computed and returned. In the main function, we declared and initialized variables for sides and height as a, b, and h respectively with values 5, 6, and 8. We invoked the function area with a, b, and c as arguments and loaded the returned output into a variable d. Finally, printed the area using the print function.

## Conclusion

In this tutorial, we discussed different ways to implement the program to compute the area of the trapezium in the Haskell programming language.

- Related Articles
- Java Program to Find the Area of a Trapezium
- Swift Program To Find The Area of a Trapezium
- Kotlin Program To Find The Area of a Trapezium
- Haskell Program to Find the Area of a parallelogram
- Haskell Program to Find the Area of a Square
- Haskell Program to Find the Area of a Rectangle
- How To Find The Area of a Trapezium in Golang?
- Haskell Program to Find the Surface area and Volume of Cuboid
- Program to calculate area and perimeter of Trapezium
- Haskell Program to calculate the area of Cube
- If the parallel sides of a trapezium are doubled, distance between them remaining same, then find the ratio of the area of the new trapezium to the area of the given trapezium.
- Haskell Program to calculate the area of the rhombus
- Haskell Program to calculate the volume and area of Cone
- Haskell Program to calculate the volume and area of Sphere
- Haskell Program to calculate the volume and area of the Cylinder