# C program to calculate the area of Trapezium

Here, we are going to learn how to calculate the area of Trapezium using C program?
Submitted by Nidhi, on August 05, 2021

## Problem statement

Read the base1, base2, and height of Trapezium from the user, and then calculate the area of Trapezium.

Area of Trapezium formula = h/2(b1+b2)

Where h is the height, b1 is the base1, and b2 is the base2.

## C program to calculate the area of Trapezium

The source code to calculate the area of Trapezium is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.

```// C program to calculate the area of Trapezium

#include <stdio.h>

float calcuateAreaOfTrapezium(float base1, float base2, float height)
{
float result = 0.0F;

result = 0.5 * (base1 + base2) * height;

return result;
}

int main()
{
float base1 = 0;
float base2 = 0;
float height = 0;
float area = 0;

printf("Enter base1: ");
scanf("%f", &base1);

printf("Enter base2: ");
scanf("%f", &base2);

printf("Enter height: ");
scanf("%f", &height);

area = calcuateAreaOfTrapezium(base1, base2, height);

printf("Area of Trapezium is: %f\n", area);

return 0;
}
```

### Output

```RUN 1:
Enter base1: 2
Enter base2: 3
Enter height: 4
Area of Trapezium is: 10.000000

RUN 2:
Enter base1: 1
Enter base2: 2
Enter height: 3
Area of Trapezium is: 4.500000

RUN 3:
Enter base1: 3
Enter base2: 4
Enter height: 1
Area of Trapezium is: 3.500000
```

### Explanation

In the above program, we created two functions calcuateAreaOfTrapezium() and main(). The calcuateAreaOfTrapezium() function is used to calculate the area of trapezium based on given base1, base2, and height.

In the main() function, we read the base1, base2, and height of trapezium from the user. Then we called the calcuateAreaOfTrapezium() function to calculate the area of the trapezium. After that, we printed the result on the console screen.