float calcAreaOfTrapezoid(float base1, float base2, float height);
int main() {
float base1, base2, height;
// Input from user
printf("Enter bases (base1 base2) and height (separated by spaces): "); scanf("%f %f %f", &base1
, &base2
, &height
);
// Calculate and display area
float area = calcAreaOfTrapezoid(base1, base2, height);
printf("Area of trapezoid with bases %.2f & %.2f (height %.2f): %.2f", base1, base2, height, area);
return 0;
}
// Function implementation
float calcAreaOfTrapezoid(float base1, float base2, float height) {
return (base1 + base2) / 2.0 * height;
}
ZmxvYXQgY2FsY0FyZWFPZlRyYXBlem9pZChmbG9hdCBiYXNlMSwgZmxvYXQgYmFzZTIsIGZsb2F0IGhlaWdodCk7CgppbnQgbWFpbigpIHsKICAgIGZsb2F0IGJhc2UxLCBiYXNlMiwgaGVpZ2h0OwogICAgCiAgICAvLyBJbnB1dCBmcm9tIHVzZXIKICAgIHByaW50ZigiRW50ZXIgYmFzZXMgKGJhc2UxIGJhc2UyKSBhbmQgaGVpZ2h0IChzZXBhcmF0ZWQgYnkgc3BhY2VzKTogIik7CiAgICBzY2FuZigiJWYgJWYgJWYiLCAmYmFzZTEsICZiYXNlMiwgJmhlaWdodCk7CiAgICAKICAgIC8vIENhbGN1bGF0ZSBhbmQgZGlzcGxheSBhcmVhCiAgICBmbG9hdCBhcmVhID0gY2FsY0FyZWFPZlRyYXBlem9pZChiYXNlMSwgYmFzZTIsIGhlaWdodCk7CiAgICBwcmludGYoIkFyZWEgb2YgdHJhcGV6b2lkIHdpdGggYmFzZXMgJS4yZiAmICUuMmYgKGhlaWdodCAlLjJmKTogJS4yZiIsCiAgICAgICAgICAgYmFzZTEsIGJhc2UyLCBoZWlnaHQsIGFyZWEpOwogICAgCiAgICByZXR1cm4gMDsKfQoKLy8gRnVuY3Rpb24gaW1wbGVtZW50YXRpb24KZmxvYXQgY2FsY0FyZWFPZlRyYXBlem9pZChmbG9hdCBiYXNlMSwgZmxvYXQgYmFzZTIsIGZsb2F0IGhlaWdodCkgewogICAgcmV0dXJuIChiYXNlMSArIGJhc2UyKSAvIDIuMCAqIGhlaWdodDsKfQ==