Area of a triangle inscribed in a rectangle which is inscribed in an ellipse
Given here is an ellipse with axes length 2a and 2b, which inscribes a rectangle of length l and breadth h, which in turn inscribes a triangle.The task is to find the area of this triangle.
Examples:
Input: a = 4, b = 3
Output: 12
Input: a = 5, b = 2
Output: 10
Approach:
We know the Area of the rectangle inscribed within the ellipse is, Ar = 2ab(Please refer here),
also the area of the triangle inscribed within the rectangle s, A = Ar/2 = ab(Please refer here)
Below is the implementation of the above approach:
C++
#include <bits/stdc++.h>
using namespace std;
float area( float a, float b)
{
if (a < 0 || b < 0)
return -1;
float A = a * b;
return A;
}
int main()
{
float a = 5, b = 2;
cout << area(a, b) << endl;
return 0;
}
|
Java
import java.io.*;
class GFG {
static float area( float a, float b)
{
if (a < 0 || b < 0 )
return - 1 ;
float A = a * b;
return A;
}
public static void main (String[] args) {
float a = 5 , b = 2 ;
System.out.println(area(a, b));
}
}
|
Python3
def area(a, b):
if (a < 0 or b < 0 ):
return - 1
A = a * b
return A
if __name__ = = '__main__' :
a = 5
b = 2
print (area(a, b))
|
C#
using System;
class GFG
{
static float area( float a, float b)
{
if (a < 0 || b < 0)
return -1;
float A = a * b;
return A;
}
static public void Main ()
{
float a = 5, b = 2;
Console.WriteLine(area(a, b));
}
}
|
PHP
<?php
function area( $a , $b )
{
if ( $a < 0 || $b < 0)
return -1;
$A = $a * $b ;
return $A ;
}
$a = 5;
$b = 2;
echo area( $a , $b );
?>
|
Javascript
<script>
function area(a , b)
{
if (a < 0 || b < 0)
return -1;
var A = a * b;
return A;
}
var a = 5, b = 2;
document.write(area(a, b));
</script>
|
Time complexity: O(1)
Auxiliary Space: O(1)
Last Updated :
28 Jun, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...