Program to find the length of Latus Rectum of a Hyperbola
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++
#include <iostream>
using namespace std;
double lengthOfLatusRectum( double A,
double B)
{
double major = 2.0 * A;
double minor = 2.0 * B;
double latus_rectum = (minor * minor)
/ major;
return latus_rectum;
}
int main()
{
double A = 3.0, B = 2.0;
cout << lengthOfLatusRectum(A, B);
return 0;
}
|
Java
import java.io.*;
class GFG{
static double lengthOfLatusRectum( double A,
double B)
{
double major = 2.0 * A;
double minor = 2.0 * B;
double latus_rectum = (minor * minor) / major;
return latus_rectum;
}
public static void main(String[] args)
{
double A = 3.0 , B = 2.0 ;
System.out.println(lengthOfLatusRectum(A, B));
}}
|
Python3
def lengthOfLatusRectum(A,B):
major = 2.0 * A
minor = 2.0 * B
latus_rectum = (minor * minor) / major
return latus_rectum
A = 3.0
B = 2.0
print ( round (lengthOfLatusRectum(A, B), 5 ))
|
C#
using System;
class GFG
{
static double lengthOfLatusRectum( double A,
double B)
{
double major = 2.0 * A;
double minor = 2.0 * B;
double latus_rectum = (minor * minor)
/ major;
return latus_rectum;
}
public static void Main ()
{
double A = 3.0, B = 2.0;
Console.WriteLine(lengthOfLatusRectum(A, B));
}}
|
Javascript
<script>
function lengthOfLatusRectum(A, B)
{
var major = 2.0 * A;
var minor = 2.0 * B;
var latus_rectum = (minor * minor) / major;
return latus_rectum;
}
var A = 3.0, B = 2.0;
document.write(lengthOfLatusRectum(A, B));
</script>
|
Time Complexity: O(1)
Auxiliary Space: O(1)
Last Updated :
24 Jun, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...