Aquí se da una elipse con ejes de longitud 2a y 2b , que inscribe un rectángulo de largo ly ancho h , que a su vez inscribe un triángulo. La tarea es encontrar el área de este triángulo.
Ejemplos:
Input: a = 4, b = 3 Output: 12 Input: a = 5, b = 2 Output: 10
Enfoque :
sabemos que el área del rectángulo inscrito dentro de la elipse es, Ar = 2ab ( consulte aquí ),
también el área del triángulo inscrito dentro del rectángulo s, A = Ar/2 = ab ( consulte aquí )
A continuación se muestra la implementación del enfoque anterior :
C++
// C++ Program to find the area of the triangle // inscribed within the rectangle which in turn // is inscribed in an ellipse #include <bits/stdc++.h> using namespace std; // Function to find the area of the triangle float area(float a, float b) { // length of a and b cannot be negative if (a < 0 || b < 0) return -1; // area of the triangle float A = a * b; return A; } // Driver code int main() { float a = 5, b = 2; cout << area(a, b) << endl; return 0; }
Java
// Java Program to find the area of the triangle // inscribed within the rectangle which in turn // is inscribed in an ellipse import java.io.*; class GFG { // Function to find the area of the triangle static float area(float a, float b) { // length of a and b cannot be negative if (a < 0 || b < 0) return -1; // area of the triangle float A = a * b; return A; } // Driver code public static void main (String[] args) { float a = 5, b = 2; System.out.println(area(a, b)); } } //This code is contributed by anuj_67..
Python3
# Python 3 Program to find the # area of the triangle inscribed # within the rectangle which in # turn is inscribed in an ellipse # Function to find the area # of the triangle def area(a, b): # length of a and b cannot # be negative if (a < 0 or b < 0): return -1 # area of the triangle A = a * b return A # Driver code if __name__ == '__main__': a = 5 b = 2 print(area(a, b)) # This code is contributed # by Surendra_Gangwar
C#
// C# Program to find the area of // the triangle inscribed within // the rectangle which in turn // is inscribed in an ellipse using System; class GFG { // Function to find the // area of the triangle static float area(float a, float b) { // length of a and b // cannot be negative if (a < 0 || b < 0) return -1; // area of the triangle float A = a * b; return A; } // Driver code static public void Main () { float a = 5, b = 2; Console.WriteLine(area(a, b)); } } // This code is contributed by ajit
PHP
<?php // PHP Program to find the area // of the triangle inscribed within // the rectangle which in turn // is inscribed in an ellipse // Function to find the // area of the triangle function area($a, $b) { // length of a and b cannot // be negative if ($a < 0 || $b < 0) return -1; // area of the triangle $A = $a * $b; return $A; } // Driver code $a = 5; $b = 2; echo area($a, $b); // This code is contributed // by Mahadev99 ?>
Javascript
<script> // javascript Program to find the area of the triangle // inscribed within the rectangle which in turn // is inscribed in an ellipse // Function to find the area of the triangle function area(a , b) { // length of a and b cannot be negative if (a < 0 || b < 0) return -1; // area of the triangle var A = a * b; return A; } // Driver code var a = 5, b = 2; document.write(area(a, b)); // This code contributed by Princi Singh </script>
Producción:
10
Complejidad del tiempo: 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