Skip to content
Related Articles

Related Articles

Program to find the length of Latus Rectum of a Hyperbola

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 24 Jun, 2021

Given two integers A and B, representing the length of the semi-major and semi-minor axes of a Hyperbola, the task is to find the length of the latus rectum of the hyperbola.

Examples:

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

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

Approach: The Latus Rectum of a hyperbola is the focal chord perpendicular to the major axis and the length of the Latus Rectum is equal to (Length of the minor axis )2/(length of major axis).

Follow the steps below to solve the given problem:

  • Find the length of the major axis of the hyperbola and store it in a variable, say major.
  • Find the length of the minor axis of the hyperbola and store it in a variable, say minor.
  • After completing the above steps, print the value of (minor*minor)/major as the resultant length of the Latus Rectum.

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 a hyperbola
double lengthOfLatusRectum(double A,
                           double B)
{
    // Store the length of major axis
    double major = 2.0 * A;
 
    // Store the length of minor axis
    double minor = 2.0 * B;
 
    // Store the length of the
    // latus rectum
    double latus_rectum = (minor * minor)
                          / major;
 
    // Return the length of the
    // latus rectum
    return latus_rectum;
}
 
// Driver Code
int main()
{
    double A = 3.0, B = 2.0;
    cout << lengthOfLatusRectum(A, B);
 
    return 0;
}


Java




// Java program for the above approach
import java.io.*;
 
class GFG{
   
// Function to calculate the length of
// the latus rectum of a hyperbola
static double lengthOfLatusRectum(double A,
                                  double B)
{
     
    // Store the length of major axis
    double major = 2.0 * A;
 
    // Store the length of minor axis
    double minor = 2.0 * B;
 
    // Store the length of the
    // latus rectum
    double latus_rectum = (minor * minor) / major;
 
    // Return the length of the
    // latus rectum
    return latus_rectum;
}
 
// Driver Code
public static void main(String[] args)
{
    double A = 3.0, B = 2.0;
     
    System.out.println(lengthOfLatusRectum(A, B));
}}
 
// This code is contributed by Dharanendra L V.


Python3




# Python program for the above approach
 
# Function to calculate the length of
# the latus rectum of a hyperbola
def lengthOfLatusRectum(A,B):
     
    # Store the length of major axis
    major = 2.0 * A
     
    # Store the length of minor axis   
    minor = 2.0 * B
     
    # Store the length of the
    # latus rectum
    latus_rectum = (minor * minor) / major
     
    # Return the length of the
    # latus rectum
    return latus_rectum
 
# Driver Code
A = 3.0
B = 2.0
print(round(lengthOfLatusRectum(A, B),5))
 
# This code is contributed by avanitrachhadiya2155


C#




// C# program for the above approach
using System;
class GFG
{
 
// Function to calculate the length of
// the latus rectum of a hyperbola
static double lengthOfLatusRectum(double A,
                           double B)
{
   
    // Store the length of major axis
    double major = 2.0 * A;
 
    // Store the length of minor axis
    double minor = 2.0 * B;
 
    // Store the length of the
    // latus rectum
    double latus_rectum = (minor * minor)
                          / major;
 
    // Return the length of the
    // latus rectum
    return latus_rectum;
}
 
// Driver Code
public static void Main ()
{
    double A = 3.0, B = 2.0;
    Console.WriteLine(lengthOfLatusRectum(A, B));
 
}}
 
// This code is contributed by ukasp.


Javascript




<script>
 
// Javascript program for the above approach
  
// Function to calculate the length of
// the latus rectum of a hyperbola
function lengthOfLatusRectum(A, B)
{
     
    // Store the length of major axis
    var major = 2.0 * A;
 
    // Store the length of minor axis
    var minor = 2.0 * B;
 
    // Store the length of the
    // latus rectum
    var latus_rectum = (minor * minor) / major;
 
    // Return the length of the
    // latus rectum
    return latus_rectum;
}
 
// Driver Code
var A = 3.0, B = 2.0;
 
document.write(lengthOfLatusRectum(A, B));
 
// This code is contributed by 29AjayKumar
 
</script>


Output: 

2.66667

 

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


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!