# Program to find Length of Latus Rectum of an Ellipse

• Last Updated : 07 Apr, 2021

Given two integers A and B, representing the length of semi-major and semi-minor axis of an Ellipse with general equation (x2 / A2) + (y2 / B2) = 1, the task is to find the length of the latus rectum of the ellipse

Examples:

Input: A = 3, B = 2
Output: 2.66666

Input: A = 6, B = 3
Output: 3

Approach: The given problem can be solved based on the following observations:

• The Latus Rectum of an Ellipse is the focal chord perpendicular to the major axis whose length is equal to:

Ellipse

• Length of major axis is 2A.
• Length of minor axis is 2B.
• Therefore, the length of the latus rectum is:

Follow the steps below to solve the given problem:

• Initialize two variables, say major and minor, to store the length of the major-axis (= 2A) and the length of the minor-axis (= 2B) of the Ellipse respectively.
• Calculate the square of minor and divide it with major. Store the result in a double variable, say latus_rectum.
• Print the value of latus_rectum as the final result.

Below is the implementation of the above approach:

## C++

 // C++ program for the above approach#include using namespace std; // Function to calculate the length// of the latus rectum of an ellipsedouble 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 Codeint 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 approachimport java.util.*; class GFG{ // Function to calculate the length// of the latus rectum of an ellipsestatic 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 codepublic 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 ellipsedef 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 Codeif __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 approachusing 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

 
Output:
2.66667

Time Complexity: O(1)
Auxiliary Space: O(1)

My Personal Notes arrow_drop_up