Kotlin Program To Find The Area of a Trapezium



In this article, we will understand how to find the area of a trapezium. The area of a trapezium is calculated using the formula.

(height/2 * (side1 + side2))

Below is a demonstration of the same ?

Suppose our input is ?

side1 = 5
side2 = 6
height = 6

The desired output would be ?

Area of trapezium is: 33.0

Algorithm

  • Step 1 ? START.

  • Step 2 ? Declare four integer values namely side1, side2, height and myResult.

  • Step 3 ? Define the values.

  • Step 4 ? Calculate the area of the trapezium using the formula (height/2 * (side1 + side2) and store the result.

  • Step 5 ? Display the result.

  • Step 6 ? Stop.

Example 1

In this example, we will find the Area of a Trapezium with the sides and height of the trapezium. First declare and initialize the variables for the sides and height.

val side1 = 5
val side2 = 6
val height = 6

Now, find the Area of a Trapezium using the above formulae ?

val myResult = (height/2 * (side1 + side2));

Let us now see the example to find the Area of a Trapezium ?

fun main() { val side1 = 5 val side2 = 6 val height = 6 println("The length of sides of the trapezium are defined as $side1, $side2, $height") val myResult = (height/2 * (side1 + side2)); println("The area of square is: $myResult") }

Output

The length of sides of the trapezium are defined as 5, 6, 6
The area of square is: 33

Example 2

In this example, we will find the Area of a Trapezium.

fun main() { val side1 = 5 val side2 = 6 val height = 6 println("The length of sides of the trapezium are defined as $side1, $side2, $height") trapeziumArea(side1, side2, height) } fun trapeziumArea(side1: Int, side2: Int, height: Int) { val myResult = (height/2 * (side1 + side2)); println("The area of square is: $myResult") }

Output

The length of sides of the trapezium are defined as 5, 6, 6
The area of square is: 33
Updated on: 2022-10-17T08:47:26+05:30

242 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements