Given four sides of quadrilateral a, b, c, d, find the maximum area of the quadrilateral possible from the given sides .

Examples:

Input : 1 2 1 2 Output : 2.00 It is optimal to construct a rectangle for maximum area .

According to **Bretschneider’s formula**, the area of a general quadilateral is given by

Here a, b, c, d are the sides of a quadilateral, s is the semiperimeter of a quadilateral and angles are two opposite angles.

So, this formula is maximized only when opposite angles sum to pi(180) then we can use a simplified form of Bretschneider’s formula to get the (maximum) area K.

This formula is called as **Brahmagupta’s formula** .

Below is the implementation of given approach

## C++

`// CPP program to find maximum are of a ` `// quadrilateral ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `double` `maxArea(` `double` `a, ` `double` `b, ` ` ` `double` `c, ` `double` `d) ` `{ ` ` ` `// Calculating the semi-perimeter ` ` ` `// of the given quadilateral ` ` ` `double` `semiperimeter = (a + b + c + d) / 2; ` ` ` ` ` `// Applying Brahmagupta's formula to ` ` ` `// get maximum area of quadrilateral ` ` ` `return` `sqrt` `((semiperimeter - a) * ` ` ` `(semiperimeter - b) * ` ` ` `(semiperimeter - c) * ` ` ` `(semiperimeter - d)); ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `double` `a = 1, b = 2, c= 1, d = 2; ` ` ` `printf` `(` `"%.2f\n"` `,maxArea(a, b, c, d)); ` ` ` `return` `0; ` `}` |

*chevron_right*

*filter_none*

## Java

`// Java program to find maximum are of a ` `// quadrilateral ` `import` `java.io.*; ` ` ` `class` `GFG ` `{ ` ` ` `static` `double` `maxArea(` `double` `a, ` `double` `b, ` ` ` `double` `c, ` `double` `d) ` ` ` `{ ` ` ` `// Calculating the semi-perimeter ` ` ` `// of the given quadilateral ` ` ` `double` `semiperimeter = (a + b + c + d) / ` `2` `; ` ` ` ` ` `// Applying Brahmagupta's formula to ` ` ` `// get maximum area of quadrilateral ` ` ` `return` `Math.sqrt((semiperimeter - a) * ` ` ` `(semiperimeter - b) * ` ` ` `(semiperimeter - c) * ` ` ` `(semiperimeter - d)); ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `main (String[] args) ` ` ` `{ ` ` ` `double` `a = ` `1` `, b = ` `2` `, c= ` `1` `, d = ` `2` `; ` ` ` `System.out.println(maxArea(a, b, c, d)); ` ` ` `} ` `} ` ` ` `// This code is contributed by sunnysingh ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program to find maximum ` `# area of a quadrilateral ` `import` `math ` ` ` `def` `maxArea (a , b , c , d ): ` ` ` ` ` `# Calculating the semi-perimeter ` ` ` `# of the given quadilateral ` ` ` `semiperimeter ` `=` `(a ` `+` `b ` `+` `c ` `+` `d) ` `/` `2` ` ` ` ` `# Applying Brahmagupta's formula to ` ` ` `# get maximum area of quadrilateral ` ` ` `return` `math.sqrt((semiperimeter ` `-` `a) ` `*` ` ` `(semiperimeter ` `-` `b) ` `*` ` ` `(semiperimeter ` `-` `c) ` `*` ` ` `(semiperimeter ` `-` `d)) ` ` ` `# Driver code ` `a ` `=` `1` `b ` `=` `2` `c ` `=` `1` `d ` `=` `2` `print` `(` `"%.2f"` `%` `maxArea(a, b, c, d)) ` ` ` `# This code is contributed by "Sharad_Bhardwaj". ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find maximum are of a ` `// quadrilateral ` `using` `System; ` ` ` `class` `GFG { ` ` ` ` ` `static` `double` `maxArea(` `double` `a, ` `double` `b, ` ` ` `double` `c, ` `double` `d) ` ` ` `{ ` ` ` ` ` `// Calculating the semi-perimeter ` ` ` `// of the given quadilateral ` ` ` `double` `semiperimeter = (a + b + c + d) / 2; ` ` ` ` ` `// Applying Brahmagupta's formula to ` ` ` `// get maximum area of quadrilateral ` ` ` `return` `Math.Sqrt((semiperimeter - a) * ` ` ` `(semiperimeter - b) * ` ` ` `(semiperimeter - c) * ` ` ` `(semiperimeter - d)); ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `Main () ` ` ` `{ ` ` ` `double` `a = 1, b = 2, c= 1, d = 2; ` ` ` ` ` `Console.WriteLine(maxArea(a, b, c, d)); ` ` ` `} ` `} ` ` ` `// This code is contributed by vt_m. ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program to find maximum are of a ` `// quadrilateral ` ` ` `function` `maxArea( ` `$a` `, ` `$b` `, ` `$c` `, ` `$d` `) ` `{ ` ` ` ` ` `// Calculating the semi-perimeter ` ` ` `// of the given quadilateral ` ` ` `$semiperimeter` `= (` `$a` `+ ` `$b` `+ ` `$c` `+ ` `$d` `) / 2; ` ` ` ` ` `// Applying Brahmagupta's formula to ` ` ` `// get maximum area of quadrilateral ` ` ` `return` `sqrt((` `$semiperimeter` `- ` `$a` `) * ` ` ` `(` `$semiperimeter` `- ` `$b` `) * ` ` ` `(` `$semiperimeter` `- ` `$c` `) * ` ` ` `(` `$semiperimeter` `- ` `$d` `)); ` `} ` ` ` `// Driver code ` `$a` `= 1; ` `$b` `= 2; ` `$c` `= 1; ` `$d` `= 2; ` `echo` `(maxArea(` `$a` `, ` `$b` `, ` `$c` `, ` `$d` `)); ` ` ` `// This code is contributed by vt_m. ` `?> ` |

*chevron_right*

*filter_none*

Output:

2.00

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Calculate Volume, Curved Surface Area and Total Surface Area Of Cylinder
- Find area of the larger circle when radius of the smaller circle and difference in the area is given
- Maximum area of triangle having different vertex colors
- Maximum area rectangle by picking four sides from array
- Maximum of smallest possible area that can get with exactly k cut of given rectangular
- Rectangle with Maximum Area using Java Pair
- Maximum area of rectangle possible with given perimeter
- Find maximum volume of a cuboid from the given perimeter and area
- Maximum area of a Rectangle that can be circumscribed about a given Rectangle of size LxW
- Area of a polygon with given n ordered vertices
- Check if right triangle possible from given area and hypotenuse
- Program to find area of a circle
- Program to find the area of a Square
- Minimum tiles of sizes in powers of two to cover whole area
- Area of a triangle inscribed in a rectangle which is inscribed in an ellipse
- Program for Area And Perimeter Of Rectangle
- Program for Volume and Surface Area of Cube
- Program for Volume and Surface Area of Cuboid
- Area of a Circular Sector
- Calculate Volume and Surface area Of Sphere

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.