Given a rectangle of length l and breadth b, the task is to find the largest rhombus that can be inscribed in the rectangle.
Examples:
Input : l = 5, b = 4
Output : 10
Input : l = 16, b = 6
Output : 48

From the figure, we can see, the biggest rhombus that could be inscribed within the rectangle will have its diagonals equal to the length & breadth of the rectangle.
So, Area of rhombus, A = (l*b)/2
Below is the implementation of the above approach:
C++
#include <bits/stdc++.h>
using namespace std;
float rhombusarea( float l, float b)
{
if (l < 0 || b < 0)
return -1;
return (l * b) / 2;
}
int main()
{
float l = 16, b = 6;
cout << rhombusarea(l, b) << endl;
return 0;
}
|
Java
import java.io.*;
class GFG
{
static float rhombusarea( float l,
float b)
{
if (l < 0 || b < 0 )
return - 1 ;
return (l * b) / 2 ;
}
public static void main (String[] args)
{
float l = 16 , b = 6 ;
System.out.println(rhombusarea(l, b));
}
}
|
Python3
def rhombusarea(l,b):
if (l < 0 or b < 0 ):
return - 1
return (l * b) / 2
if __name__ = = '__main__' :
l = 16
b = 6
print (rhombusarea(l, b))
|
C#
using System;
class GFG
{
static float rhombusarea( float l,
float b)
{
if (l < 0 || b < 0)
return -1;
return (l * b) / 2;
}
public static void Main ()
{
float l = 16, b = 6;
Console.WriteLine(rhombusarea(l, b));
}
}
|
PHP
<?php
function rhombusarea( $l , $b )
{
if ( $l < 0 || $b < 0)
return -1;
return ( $l * $b ) / 2;
}
$l = 16; $b = 6;
echo rhombusarea( $l , $b ) . "\n" ;
|
Javascript
<script>
function rhombusarea(l,b)
{
if (l < 0 || b < 0)
return -1;
return (l * b) / 2;
}
var l = 16, b = 6;
document.write(rhombusarea(l, b));
</script>
|
Time complexity: O(1)
Auxiliary Space: O(1)