Aquí se da un semicírculo de radio r , que inscribe un rectángulo que a su vez inscribe una elipse. La tarea es encontrar el área de esta elipse más grande.
Ejemplos:
Input: r = 5 Output: 19.625 Input: r = 11 Output: 94.985
Enfoque :
- Sea el largo del rectángulo = l y el ancho del rectángulo = b
- Sea, la longitud del eje mayor de la elipse = 2x y la longitud del eje menor de la elipse = 2y
- Como sabemos, el largo y el ancho del rectángulo más grande dentro de un semicírculo son r/√2 y √2r (consulte aquí)
- Además, Área de la elipse dentro del rectángulo = (π*l*b)/4 = (πr^2/4)
A continuación se muestra la implementación del enfoque anterior :
C++
// C++ Program to find the biggest ellipse // which can be inscribed within a rectangle // which in turn is inscribed within a semicircle #include <bits/stdc++.h> using namespace std; // Function to find the area // of the biggest ellipse float ellipsearea(float r) { // the radius cannot be negative if (r < 0) return -1; // area of the ellipse float a = (3.14 * r * r) / 4; return a; } // Driver code int main() { float r = 5; cout << ellipsearea(r) << endl; return 0; }
Java
// Java Program to find the biggest ellipse // which can be inscribed within a rectangle // which in turn is inscribed within a semicircle class GFG { // Function to find the area // of the biggest ellipse static float ellipsearea(float r) { // the radius cannot be negative if (r < 0) return -1; // area of the ellipse float a = (float)((3.14f * r * r) / 4); return a; } // Driver code public static void main(String[] args) { float r = 5; System.out.println(ellipsearea(r)); } } // This code is contributed by Code_Mech.
Python3
# Python3 Program to find the biggest ellipse # which can be inscribed within a rectangle # which in turn is inscribed within a semicircle # Function to find the area of # the biggest ellipse def ellipsearea(r) : # the radius cannot be negative if (r < 0) : return -1; # area of the ellipse a = (3.14 * r * r) / 4; return a; # Driver code if __name__ == "__main__" : r = 5; print(ellipsearea(r)); # This code is contributed by Ryuga
C#
// C# Program to find the biggest ellipse // which can be inscribed within a rectangle // which in turn is inscribed within a semicircle using System; class GFG { // Function to find the area // of the biggest ellipse static float ellipsearea(float r) { // the radius cannot be negative if (r < 0) return -1; // area of the ellipse float a = (float)((3.14 * r * r) / 4); return a; } // Driver code public static void Main() { float r = 5; Console.WriteLine(ellipsearea(r)); } } // This code is contributed by Akanksha Rai
PHP
<?php // PHP Program to find the biggest ellipse // which can be inscribed within a rectangle // which in turn is inscribed within a semicircle // Function to find the area // of the biggest ellipse function ellipsearea($r) { // the radius cannot be negative if ($r < 0) return -1; // area of the ellipse $a = (3.14 * $r * $r) / 4; return $a; } // Driver code $r = 5; echo ellipsearea($r) . "\n"; // This code is contributed by Akanksha Rai ?>
Javascript
<script> // javascript Program to find the biggest ellipse // which can be inscribed within a rectangle // which in turn is inscribed within a semicircle // Function to find the area // of the biggest ellipse function ellipsearea(r) { // the radius cannot be negative if (r < 0) return -1; // area of the ellipse var a = ((3.14 * r * r) / 4); return a; } // Driver code var r = 5; document.write(ellipsearea(r)); // This code is contributed by Amit Katiyar </script>
Producción:
19.625
Tiempo Complejidad: O(1)
Espacio Auxiliar: O(1)
Publicación traducida automáticamente
Artículo escrito por IshwarGupta y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA