The Wayback Machine - https://web.archive.org/web/20240930202654/https://www.geeksforgeeks.org/program-find-area-trapezoid/
Open In App

Program to find area of a Trapezoid

Last Updated : 17 Feb, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Definition of Trapezoid : 
A 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. 
 


In the above figure CD || AB, so they form the bases and the other two sides i.e., AD and BC form the legs. 
The area of a trapezoid can be found by using this simple formula : 
 

Area=\frac{a+b}{2}h


a = base 
b = base 
h = height 
Examples : 
 

Input : base1 = 8, base2 = 10, height = 6
Output : Area is: 54.0

Input :base1 = 4, base2 = 20, height = 7
Output :Area is: 84.0


 


 

C++

// C++ program to calculate
// area of a trapezoid
#include<bits/stdc++.h>
using namespace std;
  
// Function for the area
double Area(int b1, int b2, 
                    int h)
{
    return ((b1 + b2) / 2) * h;
}
  
// Driver Code
int main()
{
    int base1 = 8, base2 = 10, 
                height = 6;
    double area = Area(base1, base2, 
                            height);
    cout << "Area is: " << area;
    return 0;
}
  
// This code is contributed by shivanisinghss2110

                    

C

// CPP program to calculate
// area of a trapezoid
#include <stdio.h>
  
// Function for the area
double Area(int b1, int b2, 
                    int h)
{
    return ((b1 + b2) / 2) * h;
}
  
// Driver Code
int main()
{
    int base1 = 8, base2 = 10, 
                   height = 6;
    double area = Area(base1, base2, 
                              height);
    printf("Area is: %.1lf", area);
    return 0;
}

                    

Java

// Java program to calculate
// area of a trapezoid
import java.io.*;
  
class GFG
{
      
    // Function for the area
    static double Area(int b1, 
                       int b2, 
                       int h)
    {
        return ((b1 + b2) / 2) * h;
    }
  
    // Driver Code
    public static void main (String[] args)
    {
        int base1 = 8, base2 = 10, 
                       height = 6;
        double area = Area(base1, base2, 
                                  height);
        System.out.println("Area is: " + area);
    }
}

                    

Python3

# Python program to calculate 
# area of a trapezoid
  
# Function for the area
def Area(b1, b2, h):
    return ((b1 + b2) / 2) * h
  
# Driver Code
base1 = 8; base2 = 10; height = 6
area = Area(base1, base2, height)
print("Area is:", area)

                    

C#

// C# program to calculate
// area of a trapezoid
using System;
  
class GFG 
{
      
    // Function for the area
    static double Area(int b1, 
                       int b2, 
                       int h)
    {
        return ((b1 + b2) / 2) * h;
    }
  
    // Driver Code
    public static void Main ()
    {
        int base1 = 8, base2 = 10, 
                       height = 6;
        double area = Area(base1, base2,
                                  height);
        Console.WriteLine("Area is: " + area);
    }
}
  
// This code is contributed by vt_m

                    

PHP

<?php
// PHP program to calculate
// area of a trapezoid
  
  
// Function for the area
function Area( $b1, $b2, $h)
{
    return (($b1 + $b2) / 2) * $h;
}
  
// Driver Code
  
    $base1 = 8; $base2 = 10; 
    $height = 6;
    $area = Area($base1, $base2, $height);
    echo("Area is: ");
    echo($area);
      
  
// This code is contributed by vt_m.
?>

                    

Javascript

<script>
  
// Javascript program to calculate 
// area of a trapezoid 
  
// Function for the area 
function Area(b1, b2, h) 
{ 
    return ((b1 + b2) / 2) * h; 
} 
  
// Driver Code 
    let base1 = 8, base2 = 10, 
                height = 6; 
    let area = Area(base1, base2, 
                            height); 
    document.write("Area is: " + area); 
      
// This code is contributed by Mayank Tyagi
</script>

                    

Output : 
 

Area is: 54.0


 Time complexity: O(1)

space complexity: O(1)



Previous Article
Next Article

Similar Reads

Area of circle inscribed in a Isosceles Trapezoid
Given two bases of the isosceles trapezoid ABCD as a and b, the task is to find the area of circle inscribed in this trapezoid  Examples:   Input: a = 10, b = 30 Output: Area = 235.57Input: a = 20, b = 36 Output: Area = 565.38Derivation: Given a circle inscribed in trapezium ABCD (sides AB = n and CD = m), we need to find out the height of the trap
5 min read
Program to find height of a Trapezoid
Given two integers a and b representing the length of the two bases, and the two integers p1 and p2 representing the non-parallel sides of a trapezoid, the task is to find the height of the trapezoid. A 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 othe
5 min read
Largest trapezoid that can be inscribed in a semicircle
Given a semicircle of radius r, the task is to find the largest trapezoid that can be inscribed in the semicircle, with base lying on the diameter.Examples: Input: r = 5 Output: 32.476 Input: r = 8 Output: 83.1384 Approach: Let r be the radius of the semicircle, x be the lower edge of the trapezoid, and y the upper edge, & h be the height of th
4 min read
Find area of the larger circle when radius of the smaller circle and difference in the area is given
Given two integers r and d where r is the radius of the smaller circle and d is the difference of the area of this circle with some larger radius circle. The task is to find the area of the larger circle.Examples: Input: r = 4, d = 5 Output: 55.24 Area of the smaller circle = 3.14 * 4 * 4 = 50.24 55.24 - 50.24 = 5Input: r = 12, d = 3 Output: 455.16
4 min read
Find area of the Circle when the area of inscribed Square is given
Given the area of a square inscribed in a circle as N, the task is to calculate the area of a circle in which the square is inscribed. Examples: Input: N = 4 Output: 6.283 Input: N = 10Output: 15.707 Approach: Consider the below image: Let the area of the square is 'A'The side of the square is given by = A**(1/2)A right-angled triangle is formed by
4 min read
Calculate Volume, Curved Surface Area and Total Surface Area Of Cylinder
Given radius and height of Cylinder, calculate the volume, total surface area and curved surface area of cylinder. Volume of Cylinder: The volume of cylinder is defined as the amount of three dimensional space occupied by the cylinder or the storage capacity of a cylinder. We can calculate volume of cylinder by using formula: where ' r 'is radius o
7 min read
Radius of a circle having area equal to the sum of area of the circles having given radii
Given two integers r1 and r2, representing the radius of two circles, the task is to find the radius of the circle having area equal to the sum of the area of the two circles having given radii. Examples: Input:r1 = 8r2 = 6Output:10Explanation:Area of circle with radius 8 = 201.061929 Area of a circle with radius 6 = 113.097335Area of a circle with
5 min read
Check if an area P can be obtained from an area of N * M
Given integers N, M and P, the task is to check if is possible to find a rectangular area of P sq. units inside a rectangular area of N × M sq units. Examples: Input: N = 3, M = 3, P = 4Output: YESExplanation: Rectangle of 2 x 2 sq. unit area Input: N = 4, M = 4, P = 7Output: NO Approach: Follow the steps below to solve the problem Find all the fac
6 min read
Program to find the Area of an Ellipse
Given an ellipse with a semi-major axis of length a and semi-minor axis of length b. The task is to find the area of an ellipse.In mathematics, an ellipse is a curve in a plane surrounding by two focal points such that the sum of the distances to the two focal points is constant for every point on the curve or we can say that it is a generalization
4 min read
Program to find the Area and Volume of Icosahedron
Given the side of an Icosahedron. The task is to find the area and volume of the given Icosahedron.Examples : Input : a = 5 Output : Area: 216.506 Volume: 272.712 Input : a = 10 Output : Area: 866.0254 Volume: 2181.695 In geometry, an Icosahedron is a regular polyhedron which contains 20 identical equilateral triangular faces, 30 sides, and 12 vert
5 min read
Program to find the surface area of the square pyramid
Given the base length(b) and slant height(s) of the square pyramid. The task is to find the surface area of the Square Pyramid. A Pyramid with a square base, 4 triangular faces, and an apex is a square pyramid. In this figure, b – base length of the square pyramid. s – slant height of the square pyramid. h – height of the square pyramid.Examples: I
3 min read
Program to find volume and surface area of pentagonal prism
A prism that has 5 rectangular faces and 2 parallel pentagonal bases is a pentagonal prism. So you are given the apothem length(a), base length(b) and height(h) of the pentagonal prism. you have to find the surface area and the volume of the Pentagonal Prism.Examples: Input : a=3, b=5, h=6 Output :surface area=225, volume=225 Input : a=2, b=3, h=5
4 min read
Program to find the Area of a Parallelogram
Given the sides of a Parallelogram, task is calculate the area of a Parallelogram. Examples: Input: base = 30, height = 40 Output: 1200.000000 As Area of parallelogram = base * height, Therefore, Area = 30 * 40 = 1200.00 Approach: Area of parallelogram = base * height Below is the implementation of the above approach: C/C++ Code #include <iostre
2 min read
Program to find the Area and Perimeter of a Semicircle
Given the radius of the semicircle as r, the task is to find out the Area and Perimeter of that semicircle.Examples: Input: r = 10 Output: Area = 157.00, Perimeter = 31.4 Input: r = 25 Output: Area =981.250000, Perimeter = 78.500000 Approach: In mathematics, a semicircle is a one-dimensional locus of points that forms half of a circle. The area of
5 min read
Program to find Area of Triangle inscribed in N-sided Regular Polygon
Given the triangle inscribed in an N-sided regular polygon with given side length, formed using any 3 vertices of the polygon, the task is to find the area of this triangle. Examples: Input: N = 6, side = 10 Output: 129.904 Input: N = 8, side = 5 Output: 45.2665 Approach: Consider the 1st example: Given is a 6 sided regular polygon ABCDEF with a tr
6 min read
Program to find Surface Area and Volume of Octagonal Prism
Given the base length, height, and distance of Octagonal Prism we have to find the Surface Area and Volume of the octagonal prism for the given parameters. The octagonal prism is a solid three-dimensional object having a total of 10 faces, 24 edges, and 16 vertices. The two faces at either end are octagons and the rest of the faces are rectangular.
5 min read
Program to find all possible triangles having same Area and Perimeter
The task is to find all possible triangles having the same perimeter and area. Examples: The triangle having sides (6, 8, 10) have the same perimeter (= (6 + 8 + 10) = 24) and area (= 0.5 * 6 * 8 = 24). Approach: The idea is based on the observation from Heron's Formula. Below are the observations: Let the sides of the triangle be a, b, c.Perimeter
9 min read
JavaScript program to find Area and Perimeter of Rectangle
A rectangle is a flat figure in a plane. It has four sides and four equal angles of 90 degrees each. In a rectangle all four sides are not of equal length like a square, sides opposite to each other have equal length. Both diagonals of the rectangle have equal lengths. Examples: Input: 4 5 Output: Area = 20 Perimeter = 18 Input: 2 3 Output: Area =
1 min read
Program to find area of a triangle
Given the sides of a triangle, the task is to find the area of this triangle. Examples : Input : a = 5, b = 7, c = 8 Output : Area of a triangle is 17.320508 Input : a = 3, b = 4, c = 5 Output : Area of a triangle is 6.000000Recommended PracticeArea of a triangleTry It! Approach: The area of a triangle can simply be evaluated using following formul
10 min read
Program to find the area of a Square
What is a square ? Square is a flat shape, in one plane, defined by four points at the four corners. A square has four sides all of equal length, and four corners, all right angles (90 degree angles). A square is a kind of rectangle but with all sides equal. Formula : [Tex]Area = side * side [/Tex]Examples: Input : 4 Output :16 Input :8 Output :64
3 min read
Program to find area of a Circular Segment
In a circle, if a chord is drawn then that chord divides the whole circle into two parts. These two parts of the circle are called segments of the circle. The smaller area is known as the Minor segment and the larger area is called as the Major segment.In the figure below, the chord AB divides the circle into minor and major segments. We are given
6 min read
Program to find area of a circle
Given the radius of a circle, find the area of that circle. The area of a circle can simply be evaluated using the following formula.    [Tex]Area = \pi r^2[/Tex] where r is radius of circle and it maybe in float because value of pie is 3.14    Approach: Using the given radius, find the area using the above formula: (pi * r * r) and print the resul
3 min read
JavaScript program to find area of a circle
Learn how to calculate the area of a circle using JavaScript with this easy guide. We will show you a simple JavaScript program that does the math for you. Whether you're new to coding or looking for a quick refresher, this article has got you covered. Given the radius of a circle, find the area of that circle. The area of a circle can simply be ev
2 min read
Program to calculate area and perimeter of Trapezium
A trapezium is a quadrilateral with at least one pair of parallel sides, other two sides may not be parallel. The parallel sides are called the bases of the trapezium and the other two sides are called it's legs. The perpendicular distance between parallel sides is called height of trapezium. Formula : Area of Trapezium : 0.5 * (a + b) * h Perimete
5 min read
Program to calculate area and volume of a Tetrahedron
A Tetrahedron is simply a pyramid with a triangular base. It is a solid object with four triangular faces, three on the sides or lateral faces, one on the bottom or the base and four vertices or corners. If the faces are all congruent equilateral triangles, then the tetrahedron is called regular. The area of Tetrahedron can be found by using the fo
5 min read
Program to calculate area and perimeter of equilateral triangle
An equilateral triangle is a triangle in which all three sides and angles are equal. All three internal angles of equilateral triangle measures 60 degree. If we know the length of each sides of equilateral triangle, then we can use below mentioned formula to calculate area of equilateral triangle.Area of Equilateral Triangle = (sqrt(3)/4) * a * a I
4 min read
Program to calculate Area Of Octagon
A regular octagon is a closed figure with sides of the same length and internal angles of the same size. It has eight lines of reflective symmetry and rotational symmetry of order 8. The internal angle at each vertex of a regular octagon is 135°. The central angle is 45°.Properties : Convex polygon, Equilateral polygon, Isogonal figure, Isotoxal fi
3 min read
Program for Surface Area of Octahedron
Given the sides of Octahedron then calculate the surface area. Examples: Input : 7 Output : 169.741 Input : 9 Output : 280.59 An regular octahedron has eight faces, which are all in the shape of equilateral triangles.The area of an octahedron is 2 multiplied by the length of an edge squared multiplied by the square root of three. Formula: Surface a
2 min read
Program for Surface area of Dodecahedron
Given the edge of the dodecahedron calculate its surface area. Surface area is the amount of space that all the faces of the shape take up.Formula: [Tex]\mathbf{A=3\sqrt{25+10\sqrt{5}}\hspace{2 mm} a^{2}} [/Tex]Examples: Input: 3 Output: 185.812 Input: 7 Output: 1011.64 A dodecahedron is a 3-dimensional figure made up of 12 faces, or flat sides. Al
3 min read
Program to calculate area of Circumcircle of an Equilateral Triangle
Given the length of sides of an equilateral triangle. We need to write a program to find the area of Circumcircle of the given equilateral triangle.Examples: Input : side = 6 Output : Area of circumscribed circle is: 37.69 Input : side = 9 Output : Area of circumscribed circle is: 84.82 All three sides of equilateral triangle are of equal length an
4 min read