Area of largest triangle that can be inscribed within a rectangle in C Program?

Suppose one rectangle is given. We know the length L and breadth B of it. We have to find the area of largest triangle that can be inscribed within that rectangle −

Length (L) Breadth (B)

The largest triangle that can be inscribed within a rectangle will always be half of the rectangle's area. This triangle uses the full length and breadth of the rectangle as its base and height.

Syntax

Area = (Length × Breadth) / 2

Example

Here's a C program to calculate the area of the largest triangle that can be inscribed within a rectangle −

#include <stdio.h>

float area(float l, float b) {
   if (l < 0 || b < 0) /* if the values are negative it is invalid */
      return -1;
   float area = (l * b) / 2;
   return area;
}

int main() {
   float length = 10, breadth = 8;
   float result = area(length, breadth);
   
   if (result == -1) {
      printf("Invalid input: Length and breadth must be positive<br>");
   } else {
      printf("Length: %.1f, Breadth: %.1f<br>", length, breadth);
      printf("Area of largest inscribed triangle: %.1f<br>", result);
   }
   
   return 0;
}

Output

Length: 10.0, Breadth: 8.0
Area of largest inscribed triangle: 40.0

Key Points

  • The largest triangle inscribed in a rectangle always has an area equal to half the rectangle's area.
  • The triangle uses the rectangle's full dimensions as its base and height.
  • Input validation ensures that negative dimensions return an error value.

Conclusion

The area of the largest triangle that can be inscribed within a rectangle is simply half the area of the rectangle. This relationship makes the calculation straightforward using the formula (L × B) / 2.

Updated on: 2026-03-15T11:46:27+05:30

213 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements