Open In App

JavaScript Program to Find the Area of Trapezium

Last Updated : 26 Dec, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

A Trapezium or (Trapezoid) is a convex quadrilateral with at least one pair of parallel sides. The parallel sides are called the bases of the trapezoid and the other two sides which are not parallel are referred to as the legs. There can also be two pairs of bases.  

The area of a trapezium can be found by using this simple formula : 

Area = (a+b)/2*h
a = base 
b = base 
h = height 

Example:

Input : base1 = 15, base2 = 30, height = 10
Output: area is: 225

Input : base1 = 20, base2 = 20, height = 50
Output: area is: 1000

Approach:

  • Declare and initialize variables for the two bases (base1 and base2) and the height (height) of the trapezium.
  • Calculate the area of the trapezium using the formula: Area = 1/2*(sum of parallel sides)*height of the trapezium.
  • Display or store the calculated area.
  • End of the code.

Example: Below is the function to find area of trapezium.

Javascript




// Javascript program to calculate
// area of a trapezoid
 
// Function for the area
function Area(b1, b2, h) {
    return ((b1 + b2) / 2) * h;
}
let base1 = 8, base2 = 10,
    height = 6;
let area = Area(base1, base2,
    height);
console.log("Area is: ", area);


Output

Area is:  54

Time complexity: O(1)

Auxilitary Space complexity: O(1)


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads