Dados dos números enteros A y B, que representan la longitud del eje semi-mayor y semi-menor de una Elipse con ecuación general (x 2 / A 2 ) + (y 2 / B 2 ) = 1 , la tarea es encontrar la longitud del latus rectum de la elipse
Ejemplos:
Entrada: A = 3, B = 2
Salida: 2.66666Entrada: A = 6, B = 3
Salida: 3
Enfoque: El problema dado se puede resolver con base en las siguientes observaciones:
- El Latus Rectum de una Elipse es la cuerda focal perpendicular al eje mayor cuya longitud es igual a:
- La longitud del eje mayor es 2A.
- La longitud del eje menor es 2B.
- Por lo tanto, la longitud del latus rectum es:
Siga los pasos a continuación para resolver el problema dado:
- Inicialice dos variables, digamos mayor y menor, para almacenar la longitud del eje mayor (= 2A ) y la longitud del eje menor (= 2B ) de la Elipse respectivamente.
- Calcula el cuadrado de menor y divídelo con mayor. Almacene el resultado en una variable doble, digamos latus_rectum .
- Imprime el valor de latus_rectum como resultado final.
A continuación se muestra la implementación del enfoque anterior:
C++
// C++ program for the above approach #include <iostream> using namespace std; // Function to calculate the length // of the latus rectum of an ellipse double lengthOfLatusRectum(double A, double B) { // Length of major axis double major = 2.0 * A; // Length of minor axis double minor = 2.0 * B; // Length of the latus rectum double latus_rectum = (minor*minor)/major; return latus_rectum; } // Driver Code int main() { // Given lengths of semi-major // and semi-minor axis double A = 3.0, B = 2.0; // Function call to calculate length // of the latus rectum of a ellipse cout << lengthOfLatusRectum(A, B); return 0; }
Java
// Java program for the above approach import java.util.*; class GFG{ // Function to calculate the length // of the latus rectum of an ellipse static double lengthOfLatusRectum(double A, double B) { // Length of major axis double major = 2.0 * A; // Length of minor axis double minor = 2.0 * B; // Length of the latus rectum double latus_rectum = (minor * minor) / major; return latus_rectum; } // Driver code public static void main(String[] args) { // Given lengths of semi-major // and semi-minor axis double A = 3.0, B = 2.0; // Function call to calculate length // of the latus rectum of a ellipse System.out.print(lengthOfLatusRectum(A, B)); } } // This code is contributed by susmitakundugoaldanga
Python3
# Python3 program for the above approach # Function to calculate the length # of the latus rectum of an ellipse def lengthOfLatusRectum(A, B): # Length of major axis major = 2.0 * A # Length of minor axis minor = 2.0 * B # Length of the latus rectum latus_rectum = (minor*minor)/major return latus_rectum # Driver Code if __name__ == "__main__": # Given lengths of semi-major # and semi-minor axis A = 3.0 B = 2.0 # Function call to calculate length # of the latus rectum of a ellipse print('%.5f' % lengthOfLatusRectum(A, B)) # This code is contributed by ukasp.
C#
// C# program for the above approach using System; class GFG { // Function to calculate the length // of the latus rectum of an ellipse static double lengthOfLatusRectum(double A, double B) { // Length of major axis double major = 2.0 * A; // Length of minor axis double minor = 2.0 * B; // Length of the latus rectum double latus_rectum = (minor*minor)/major; return latus_rectum; } // Driver Code public static void Main() { // Given lengths of semi-major // and semi-minor axis double A = 3.0, B = 2.0; // Function call to calculate length // of the latus rectum of a ellipse Console.WriteLine(lengthOfLatusRectum(A, B)); } } // This code is contributed by souravghosh0416.
Javascript
<script> // Javascript program for the above approach // Function to calculate the length // of the latus rectum of an ellipse function lengthOfLatusRectum(A, B) { // Length of major axis var major = 2.0 * A; // Length of minor axis var minor = 2.0 * B; // Length of the latus rectum var latus_rectum = (minor * minor) / major; return latus_rectum; } // Driver code // Given lengths of semi-major // and semi-minor axis var A = 3.0, B = 2.0; document.write(lengthOfLatusRectum(A, B)); // This code is contributed by Ankita saini </script>
Producción:
2.66667
Tiempo Complejidad: O(1)
Espacio Auxiliar: O(1)