Q:

Program to find the area and perimeter of trapezium

0

In this article, we will see the programs to find the area and perimeter of the trapezium in different programming languages.

But before writing the programs, let's first see a brief description of the trapezium and the formulae to find its area and perimeter.

Trapezium

The trapezium (also called trapezoid) is a geometrical shape that includes four sides in which a pair of opposite sides is parallel. The parallel sides are known as base, and the non-parallel sides are known as leg. The parallel sides can be horizontal, vertical, or slanting (diagonal).

It is a convex quadrilateral shape. It means that a closed shape with four sides along with one pair of parallel sides.

The representation of the trapezium is shown in the below image -

Area of trapezium

The formula for finding the area of the trapezium are given as follows -

 

Area of trapezium (A) = ½ (b1 + b2) * h  

Or,  

Area of trapezium (A) = h/2 * (b1 + b2)  

Or,  

Area of trapezium (A) = h * (b1 + b2/2)  

Perimeter of trapezium

The perimeter of a trapezium is the sum of all its sides. The formula for finding the perimeter of the trapezium with sides AB, BC, CD, and DA are given as follows -

 

Perimeter of trapezium = Sum of all sides = AB + BC + CD + DA  

If AB = a, BC = b, CD = c, DA = d, the perimeter of trapezium will be -

 

Perimeter of trapezium = Sum of all sides = a + b + c + d  

Now, let's see the programs to find the area and perimeter of the trapezium.

Programs to find the area and perimeter of trapezium

In the programs, we are using the following formulae to calculate the area and perimeter of trapezium -

 

Area of trapezium = ½ * (a + b) * h (Where, 'a' and 'b' are the parallel sides of trapezium, and 'h' is the perpendicular distance between parallel sides)  

Perimeter of trapezium = a + b + c + d (Where, 'a', 'b', 'c', and 'd' are the sides of trapezium) 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program: Write a program to find the area and perimeter of the trapezium in C language.

#include <stdio.h>  
int area(int a, int b, int h)  
{  
return 0.5 * (a + b) * h; //'a' and 'b' are the parallel sides, and 'h' is the perpendicular distance   
}  
int perimeter(int a, int b, int c, int d)  
{  
    return (a + b + c + d);  
}  
int main()  
{  
    int a = 3, b = 4, c = 6, d = 5, h = 6;  
    printf("a = %d, b = %d, c = %d, d = %d, h = %d\n", a, b, c, d, h);  
    printf("Area of Trapezium is: %d\n", area(a, b, h));  
    printf("Perimeter of Trapezium is: %d", perimeter(a, b, c, d));  
    return 0;  
}  

Output:

 

Program: Write a program to find the area and perimeter of the trapezium in the C# language.

using System;  
  
class Jtp {  
public static int area(int a, int b, int h)  
{  
return (h/2 * (a + b)); //'a' and 'b' are the parallel sides, and 'h' is the perpendicular distance   
}   
    public static int perimeter(int a, int b, int c, int d)  
    {  
        return (a + b + c + d);  
    }  
    public static void Main()  
    {  
        int a = 3, b = 4, c = 6, d = 5, h = 6;  
        Console.WriteLine("a = " + a + ", b = " + b + ", c = " + c + ", d = " + d + ", h = " + h);  
        Console.WriteLine("Area of Trapezium is: " + area(a, b, h));  
        Console.WriteLine("Perimeter of Trapezium is: " + perimeter(a, b, c, d));  
    }  
  
}  

Output:

 

Program: Write a program to find the area and perimeter of the trapezium in Java.

public class Trapezium {  
public static int area(int a, int b, int h)  
{  
return (h/2 * (a + b)); //'a' and 'b' are the parallel sides, and 'h' is the perpendicular distance   
}  
public static int perimeter(int a, int b, int c, int d)  
{  
return (a + b + c + d); //'a', 'b', 'c', and 'd' are the sides of trapezium  
}  
public static void main(String args[])  
{  
    int a = 3, b = 4, c = 6, d = 5, h = 6;  
    System.out.println();  
    System.out.println("a = " + a + ", b = " + b + ", c = " + c + ", d = " + d + ", h = " + h);  
    System.out.println("Area of Trapezium is: " + area(a, b, h));  
    System.out.println("Perimeter Of Trapezium is: " + perimeter(a, b, c, d));  
}  
}  

Output:

After compiling the file on command prompt, and after execution, the output will be -

 

Program: Write a program to find the area and perimeter of trapezium in JavaScript.

<!DOCTYPE html>  
<html>  
   <body>  
<script>  
function area(a, b, h)  
{  
    return (0.5 * (a + b) * h);  
}  
function perimeter(a, b, c, d)  
{  
    return (a + b + c + d);  
}  
var a = 3, b = 4, c = 6, d = 5, h = 6;  
document.write("a = " + a + ", b = " + b + ", c = " + c + ", d = " + d + ", h = " + h + "<br>");  
document.write("Area of Trapezium is: " + area(a, b, h) + "<br>");  
document.write("Perimeter of Trapezium is: " + perimeter(a, b, c, d));  
</script>  
  
</body>  
</html>  

Output:

 

Program: Write a program to find the area and perimeter of the trapezium in C++.

#include <iostream>  
using namespace std;  
  
int area(int a, int b, int h)  
{  
return 0.5 * (a + b) * h; //'a' and 'b' are the parallel sides, and 'h' is the perpendicular distance   
}  
int perimeter(int a, int b, int c, int d)  
{  
    return (a + b + c + d);  
}  
  
int main()  
{  
    int a = 3, b = 4, c = 6, d = 5, h = 6;  
    cout<<"a = "<< a <<", b = "<< b <<", c = "<< c <<", d = "<< d <<", h = "<< h << endl;  
    cout<< "Area of Trapezium is: " << area(a, b, h) << endl;  
    cout<< "Perimeter of Trapezium is: " << perimeter(a, b, c, d);  
    return 0;  
}  

Output:

 

Program: Write a program to find the area and perimeter of trapezium in PHP.

<?php   
function area($a, $b, $h)   
{   
    return (0.5 * ($a + $b) * $h);   
}   
function perimeter($a, $b, $c, $d)   
{   
    return ($a + $b + $c + $d);   
}   
$a = 3; $b = 4; $c = 6; $d = 5; $h = 6;   
echo("a = ". $a .", b = ". $b .", c = ". $c .", d = ". $d .", h = ". $h ."<br/>");  
echo ("Area of Trapezium is: ". area($a, $b, $h)."<br/>");   
echo("Perimeter of Trapezium is: ". perimeter($a, $b, $c, $d));   
?>  

Output:

 

Program: Write a program to find the area and perimeter of trapezium in python.

def area(a, b, h):   
    return (0.5 * (a + b) * h)   
def perimeter(a, b, c, d):   
    return (a + b + c + d)   
a = 3  
b = 4  
c = 6  
d = 5  
h = 6  
print("a =", a)  
print("b =", b)  
print("c =", c)  
print("d =", d)  
print("h =", h)  
print("Area of Trapezium =", area(a, b, h))   
print("Perimeter of Trapezium =", perimeter(a, b, c, d))  

Output:

 

So, that's all about the article. Here, we have discussed the programs to find the area and perimeter of the trapezium in CC++JavaC#PHPpython, and JavaScript. Hope you find the article helpful and informative.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now