Program to calculate area and perimeter of Trapezium



Trapezium is a type of quadrilateral that has at least one pair of side parallel to each other. Area and perimeter of a trapezium can be found using the below formula,

Perimeter = sum of all sides

Area = ½ x (sum of the lengths of the parallel sides) x perpendicular distance between parallel sides

Code logic − The code will use 5 variables in as all sides of trapezium and one for the perpendicular distance between the two parallel side. For the area variable calculation we will take a float variable that will be initialised with the value. To calculate it we will use the formula “ ½ x (sum of length of parallel sides) x perpendicular distance between parallel sides ”. For the perimeter calculation a variable will be assigned the expression, “(Sum of all sides)”.

Below code displays the program to calculate the area and perimeter of a trapezium,

Example

 Live Demo

#include <stdio.h>
int main() {
   int a = 2 , b = 3 , c = 5 , d = 4, h = 5;
   float area, perimeter;
   printf("The sides of trapezium are %d , %d , %d , %d 
", a,b,c,d);    printf("Distance between two parallel sides is %d
", h);    perimeter = a+b+c+d;    area = 0.5 * (a + b) * h ;    printf("Perimeter of the trapezium is %.1f
", perimeter);    printf("Area of the trapezium is: %.3f", area);    return 0; }

Output

The sides of trapezium are 2 , 3 , 5 , 4
Distance between two parallel sides is 5
Perimeter of the trapezium is 14.0
Area of the trapezium is: 12.500
karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know


Advertisements