Area of the biggest ellipse inscribed within a rectangle

Given here is a rectangle of length l & breadth b, the task is to find the area of the biggest ellipse that can be inscribed within it.
Examples:
Input: l = 5, b = 3 Output: 11.775 Input: 7, b = 4 Output: 21.98
Approach:
- Let, the length of the major axis of the ellipse = 2x and the length of the minor axis of the ellipse = 2y
- From the diagram, it is very clear that,
2x = l
2y = b
- So, Area of the ellipse = (? * x * y) = (? * l * b) / 4
Below is the implementation of the above approach:
C++
// C++ Program to find the biggest ellipse// which can be inscribed within the rectangle#include <bits/stdc++.h>using namespace std;// Function to find the area// of the ellipsefloat ellipse(float l, float b){ // The sides cannot be negative if (l < 0 || b < 0) return -1; // Area of the ellipse float x = (3.14 * l * b) / 4; return x;}// Driver codeint main(){ float l = 5, b = 3; cout << ellipse(l, b) << endl; return 0;} |
Java
// Java Program to find the biggest rectangle // which can be inscribed within the ellipse import java.util.*; import java.lang.*; import java.io.*; class GFG{ // Function to find the area // of the rectangle static float ellipse(float l, float b) { // a and b cannot be negative if (l < 0 || b < 0) return -1; float x = (float)(3.14 * l * b) / 4; return x; } // Driver code public static void main(String args[]) { float a = 5, b = 3; System.out.println(ellipse(a, b)); } } // This code is contributed// by Mohit Kumar |
Python3
# Python3 Program to find the biggest ellipse # which can be inscribed within the rectangle # Function to find the area# of the ellipse def ellipse(l, b): # The sides cannot be negative if l < 0 or b < 0: return -1 # Area of the ellipse x = (3.14 * l * b) / 4 return x # Driver code if __name__ == "__main__": l, b = 5, 3 print(ellipse(l, b)) # This code is contributed # by Rituraj Jain |
C#
// C# Program to find the biggest rectangle // which can be inscribed within the ellipse using System;class GFG{ // Function to find the area // of the rectangle static float ellipse(float l, float b) { // a and b cannot be negative if (l < 0 || b < 0) return -1; float x = (float)(3.14 * l * b) / 4; return x; } // Driver code public static void Main() { float a = 5, b = 3; Console.WriteLine(ellipse(a, b)); } } // This code is contributed// by Code_Mech. |
PHP
<?php// PHP Program to find the biggest ellipse// which can be inscribed within the rectangle// Function to find the area// of the ellipsefunction ellipse($l, $b){ // The sides cannot be negative if ($l < 0 || $b < 0) return -1; // Area of the ellipse $x = (3.14 * $l * $b) / 4; return $x;}// Driver code$l = 5; $b = 3;echo ellipse($l, $b) . "\n";// This code is contributed// by Akanksha Rai?> |
Javascript
<script>// javascript Program to find the biggest rectangle // which can be inscribed within the ellipse // Function to find the area // of the rectangle function ellipse(l , b) { // a and b cannot be negative if (l < 0 || b < 0) return -1; var x = (3.14 * l * b) / 4; return x; } // Driver code var a = 5, b = 3; document.write(ellipse(a, b)); // This code is contributed by Amit Katiyar </script> |
Output:
11.775
Time Complexity: O(1)
Auxiliary Space: O(1)
Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 zambiatek!
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 zambiatek!




