Program to find area of a Trapezoid

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

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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;
}

chevron_right


Java

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);
    }
}

chevron_right


Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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)

chevron_right


C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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

chevron_right


PHP

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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.
?>

chevron_right



Output :

Area is: 54.0


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



Improved By : vt_m