C Program to find Area of a Trapezoid

How to write C Program to find Area of a Trapezoid and Median of a Trapezoid with example. Before we step into practical C Program to find Area of a Trapezoid example, Let see the definitions and formulas behind the Median and Area of a Trapezoid

C Area of a Trapezoid

If we know the height and two base lengths then we can calculate the Area of a Trapezoid using the below formula:

Area = (a+b)/2 *h

Where a and b are the two bases and h is the height of the Trapezoid. We can calculate the median of a Trapezoid using the following formula:

Median = (a+b) / 2.

If we know the Median and height, we can calculate the Area of a Trapezoid as median*height

C Program to find Area of a Trapezoid

This C Program allows the user to enter both sides of the Trapezoid and height. By using those values, this C program will find the Area of a trapezoid and Median of a Trapezoid.

/* C Program to find Area of a Trapezoid */

#include<stdio.h>

int main()
{
  float base1, base2, height, Area, Median;
 
  printf("\n Please Enter two bases and height of the trapezium \n");
  scanf("%f %f %f", &base1, &base2, &height);

  Area = 0.5 * (base1 + base2) * height;
  Median = 0.5 * (base1+ base2);

  printf("\n Area of a trapezium = %.2f \n", Area);
  printf("\n Median of a trapezium = %.2f \n", Median);

  return 0;
}
C Program to find Area of a Trapezoid

Below printf statement will ask the user to enter base1, base and height values

printf("\n Please Enter two bases and height of the trapezium \n");

The below C Programming scanf statement will assign the user input values to respected variables. Such as first value will be assigned to base1, second value to base2 and third value to the height

scanf("%f %f %f", &base1, &base2, &height);

User Entered Values in this C Program are base1 = 6, base2 = 9 and height = 4

Area of a Trapezoid = 0.5 * (base1 + base2) * height;
Area of a Trapezoid = 0.5 * (6 + 9) * 4;
Area of a Trapezoid = 0.5 * 15 * 4;
Area of a Trapezoid = 30

Median of a Trapezoid = 0.5 * (base1+ base2);
Median of a Trapezoid = 0.5 * (6 + 9)
Median of a Trapezoid = 0.5 * 15
Median of a Trapezoid = 7.5