Suppose a rectangle is given. We know its length L and width B. We have to find the area of the largest triangle that can be inscribed within this rectangle -
The largest triangle is always half the rectangle. So it will be
#include <iostream> #include <cmath> using namespace std; float area(float l, float b) { if (l < 0 || b < 0 ) //if the valuse are negative it is invalid return -1; float area = (l*b)/2; return area; } int main() { float a = 10, b = 8; cout << "Area : " << area(a, b); }
Area : 40
The above is the detailed content of In a C program, translate the following into Chinese: What is the area of the largest triangle that can be embedded within a rectangle?. For more information, please follow other related articles on the PHP Chinese website!