C Programming

Write a Program to Find the Area of a Trapezoid in C

Trapezoids or trapeziums look like quadrilaterals characterized by having two parallel as well as two non-parallel sides. They are four-sided closed shapes with a perimeter and a surface area. The bases represent the parallel sides while the legs or lateral represent the non-parallel sides of the trapezium. The height is the difference between the pair of parallel sides.

When it comes to calculating the area of a trapezoid in mathematics, the process can be quite time-consuming. However, it is possible to simplify this calculation by developing a straightforward C program that efficiently computes the area. By taking input from the user and utilizing appropriate mathematical formulas, the program can accurately determine the area of a trapezoid.

What is a Trapezoid?

The term “trapezium” refers to a polygon with a single set of parallel sides. It isn’t clear what exactly a trapezium is. One school of mathematics claims that there can only be one pair of parallel sides in a trapezium, while another believes that there can be multiple pairs of parallel sides in a trapezium. If we consider the second definition, the parallelogram represents a trapezium according to that standard. However, the first definition doesn’t consider a parallelogram as a trapezium.

Area of a Trapezoid

The average length of two bases can be used to calculate the area of a trapezoid by multiplying it by the height. The mathematical formula for calculating the area of the trapezoid is given as.

Area = 1/2 (base1+base2) h

Here base1 and base2 represent the bases of the trapezoid while h represents the height of the trapezoid.

C Program to Determine the Trapezoid Area

The following C program will determine the area of a trapezoid.

#include<stdio.h>

int main() {

  float base1, base2, height, area;
  printf("Enter base1 of trapezoid: ");
  scanf("%f", & base1);
  printf("Enter base2 of trapezoid: ");
  scanf("%f", & base2);
  printf("Enter height of the trapezoid: ");
  scanf("%f", & height);
  area = ((base1 + base2) / 2) * height;
  printf("Area of Trapezoid: %f m²\n", area);
  return 0;


}

Conclusion

Trapezoids or trapeziums look like quadrilaterals characterized by having two parallel and two non-parallel sides. Calculating their area can be time-consuming, but it can be easier to calculate using the formula: Area = (1/2) × (base1 + base2) × height. A C program can efficiently compute the area by taking user input and applying the formula. By utilizing these mathematical concepts, the area of a trapezoid can be accurately determined.

About the author

Komal Batool Batool

I am passionate to research technologies and new ideas and that has brought me here to write for the LinuxHint. My major focus is to write on programming languages and computer science related topics.