- 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

# Swift Program To Find The Area of a Trapezium

This tutorial will discuss how to write a swift program to find the area of a trapezium.

A trapezium is a quadrilateral with at least a pair of opposite parallel sides. The parallel sides are known as the base and the non-parallel sides are known as the legs of the trapezium. The distance between the parallel sides is known as the height of the trapezium.

In a trapezium, an area is known as the space that is enclosed inside the boundaries of the trapezium in the two-dimensional plane. Suppose we have a board, now the area of the trapezium helps us to find how much paint we required to cover the top of the board. We can calculate the area of the trapezium with the help of the parallel sides and the distance between them.

## Algorithm to find Area of a Trapezium

**Step 1**− Define two variables**Step 2**− Enter the value of those variables**Step 3**− Perform Area of Trapezium formula for those two variables**Step 4**− Print the output

## Formula

Following is the formula of the area of a trapezium −

Area = ((X + Y)/2)H

Where,

**X and Y** represent the length of the parallel sides or bases of the trapezium as shown in the above diagram

**H** represents the height between the parallel sides

## Example 1

The following program shows how to calculate the area of a trapezium.

import Foundation import Glibc var Side1 = 12 var Side2 = 20 var Height = 10 var AreaOfTrapezium = (Side1 + Side2)*(Height / 2) print("Side 1 of Trapezium:", Side1) print("Side 2 of Trapezium:", Side2) print("Height between sides:", Height) print("Final area of the Trapezium: ", AreaOfTrapezium)

## Output

Side 1 of Trapezium: 12 Side 2 of Trapezium: 20 Height between sides: 10 Final area of the Trapezium: 160

In the above code, we find the area of the trapezium using the mathematical formula as shown in the below code −

var AreaOfTrapezium = (Side1 + Side2)*(Height / 2)

Here, the two sides of the trapezium are 12 and 20 and the height of the trapezium is 19 so the area of the trapezium is 160.

## Example 2

The following program shows how to calculate the area of the trapezium with user-defined input.

import Foundation import Glibc print("Please enter side 1-") var TrapSide1 = Int(readLine()!)! print("Please enter side 2-") var TrapSide2 = Int(readLine()!)! print("Please enter height between the two sides") var TrapHeight = Int(readLine()!)! var AreaOfTrapezium = (TrapHeight/2) * (TrapSide1 + TrapSide2) print("Entered Side 1:", TrapSide1) print("Entered Side 2:", TrapSide2) print("Entered Height:", TrapHeight) print("Final area of the Trapezium: ", AreaOfTrapezium)

## STDIN Input

Please enter side 1- 18 Please enter side 2- 14 Please enter height between the two sides 8

## Output

Entered Side 1: 18 Entered Side 2: 14 Entered Height: 8 Final area of the Trapezium: 128

In the above code, we find the area of a trapezium using the mathematical formula as shown in the below code −

var AreaOfTrapezium = (TrapHeight/2) * (TrapSide1 + TrapSide2)

Here, the height and two sides of the trapezium are given by the user at run time and using these values the area of the trapezium is calculated which is 128.

- Related Articles
- Java Program to Find the Area of a Trapezium
- Haskell Program to Find the Area of a Trapezium
- Kotlin Program To Find The Area of a Trapezium
- Swift Program to Find the Area of a Circle
- Swift Program to Find the Area of a Parallelogram
- Swift Program to Find Area of Square
- Swift Program to find the area of the rectangle
- How To Find The Area of a Trapezium in Golang?
- Program to calculate area and perimeter of Trapezium
- Swift Program to Find the Surface area and Volume of Cuboid
- 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.
- Swift Program to calculate the area of Cube
- Swift Program to Calculate the Area of Enneagon
- Swift Program to calculate the area of the rhombus
- Swift Program to Calculate Area of Octagon