# Maximum area of rectangle possible with given perimeter

Given the perimeter of a rectangle, the task is to find the maximum area of a rectangle which can use n-unit length as its perimeter.
Note: Length and Breadth must be an integral value.

Example:

```Input: perimeter = 15
Output: Maximum Area = 12

Input: perimeter = 16
Output: Maximum Area = 16
```

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Approach: For area to be maximum of any rectangle the difference of length and breadth must be minimal. So, in such case the length must be ceil (perimeter / 4) and breadth will be be floor(perimeter /4). Hence the maximum area of a rectangle with given perimeter is equal to ceil(perimeter/4) * floor(perimeter/4).

Below is the implementation of the above approach:

## C++

 `// CPP to find maximum area rectangle ` `#include ` `using` `namespace` `std; ` ` `  `// Function to find max area ` `int` `maxArea(``float` `perimeter) ` `{ ` `    ``int` `length = (``int``)``ceil``(perimeter / 4); ` `    ``int` `breadth = (``int``)``floor``(perimeter / 4); ` ` `  `    ``// return area ` `    ``return` `length * breadth; ` `} ` ` `  `// Driver code ` `int` `main() ` `{ ` `    ``float` `n = 38; ` `    ``cout << ``"Maximum Area = "` `<< maxArea(n); ` ` `  `    ``return` `0; ` `} `

## Java

 `//Java to find maximum area rectangle ` ` `  `import` `java.io.*; ` ` `  `class` `GFG { ` `// Function to find max area ` `static` `int` `maxArea(``float` `perimeter) ` `{ ` `    ``int` `length = (``int``)Math.ceil(perimeter / ``4``); ` `    ``int` `breadth = (``int``)Math.floor(perimeter / ``4``); ` ` `  `// return area ` `return` `length * breadth; ` `} ` ` `  `// Driver code ` `     `  `    ``public` `static` `void` `main (String[] args) { ` ` `  `        ``float` `n = ``38``; ` `        ``System.out.println(``"Maximum Area = "` `+ ` `                ``maxArea(n)); ` `         `  `    ``} ` `} `

## Python3

 `# Python3 program to find ` `# maximum area rectangle ` `from` `math ``import` `ceil, floor ` ` `  `# Function to find max area ` `def` `maxArea(perimeter): ` `    ``length ``=` `int``(ceil(perimeter ``/` `4``)) ` `    ``breadth ``=` `int``(floor(perimeter ``/` `4``)) ` ` `  `    ``# return area ` `    ``return` `length ``*` `breadth ` ` `  `# Driver code ` `if` `__name__ ``=``=` `'__main__'``: ` `    ``n ``=` `38` `    ``print``(``"Maximum Area ="``, maxArea(n)) `

## C#

 `// C# to find maximum area rectangle ` `using` `System; ` ` `  `class` `GFG ` `{ ` `// Function to find max area ` `static` `int` `maxArea(``float` `perimeter) ` `{ ` `    ``int` `length = (``int``)Math.Ceiling(perimeter / 4); ` `    ``int` `breadth = (``int``)Math.Floor(perimeter / 4); ` ` `  `    ``// return area ` `    ``return` `length * breadth; ` `} ` ` `  `// Driver code ` `public` `static` `void` `Main() ` `{ ` `    ``float` `n = 38; ` `    ``Console.WriteLine(``"Maximum Area = "` `+  ` `                             ``maxArea(n)); ` `} ` `} ` ` `  `// This code is contributed ` `// by Akanksha Rai(Abby_akku) `

## PHP

 ` `

Output:

```Maximum Area = 90
```

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.

My Personal Notes arrow_drop_up Discovering ways to develop a plane for soaring career goals

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.