formula to find the area of a trapezium in c
#include <stdio.h>
float area_of_trapezium(float base1, float base2, float height) {
float area = 0.5 (base1 + base2) height;
return area;
}
int main() {
float base1, base2, height;
printf("Enter the length of base 1: ");
scanf("%f", &base1);
printf("Enter the length of base 2: ");
scanf("%f", &base2);
printf("Enter the height: ");
scanf("%f", &height);
float result = area_of_trapezium(base1, base2, height);
printf("The area of the trapezium is: %.2f\n", result);
return 0;
}
This C code calculates the area of a trapezium using the formula: (\frac{1}{2} \times (base1 + base2) \times height). The area_of_trapezium
function takes three parameters: base1
, base2
, and height
, and computes the area using these values. The main
function prompts the user to input the lengths of the two bases (base1
and base2
) as well as the height of the trapezium. It then calls the area_of_trapezium
function with these values and prints the calculated area.