# Program to find Length of Latus Rectum of an Ellipse

Given two integers **A** and **B,** representing the length of semi-major and semi-minor axis of an Ellipse with general equation **(x ^{2} / A^{2}) + (y^{2} / B^{2}) = 1**, the task is to find the length of the latus rectum of the ellipse

**Examples:**

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

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

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

- The
Latus Rectumof anEllipseis the focal chord perpendicular to the major axis whose length is equal to:

- 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****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 <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>` |

**Output:**

2.66667

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

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer **Complete Interview Preparation Course****.**

In case you wish to attend **live classes **with experts, please refer **DSA Live Classes for Working Professionals **and **Competitive Programming Live for Students**.