Calculate Trapezoid Area in C, C++, and Python

The task is to compute the area of a trapeziod using different programming languages. The formula for the area of a trapezoid is (base1 + base2) * height / 2.

C code:

#include <stdio.h> #include <stdlib.h> int main() { double result = 400; printf("%.2lf", result); return 0; }

C++ code:

#include <bits/stdc++.h> using namespace std; int main() { double value; value = 150 * 2 / 15; value *= 15 + 25; value /= 2; printf("%.2f", value); return 0; }

Another C++ example:

#include <bits/stdc++.h> using namespace std; int main() { double output = 400.0; printf("%.2lf", output); return 0; }

Python code:

x = 15 y = 25 length = 150 width = length * 2 / x area = (x + y) * width / 2 print("%.2f" % area)

Tags: trapezoid area calculation C C++ python

Posted on Fri, 15 May 2026 02:03:34 +0000 by gabriellevierneza