Given two integers A and B, representing the length of the semi-major and semi-minor axis of a Hyperbola of the equation (X2 / A2) – (Y2 / B2) = 1, the task is to calculate the eccentricity of the given hyperbola.
Input: A = 3, B = 2
The eccentricity of the given hyperbola is 1.20185.
Input: A = 6, B = 3
Approach: The given problem can be solved by using the formula to find the eccentricity of an ellipse.
- The length of the semi-major axis is A.
- The length of the semi-minor axis is B.
- Therefore, the eccentricity of the ellipse is given by where A > B
Therefore, the idea is to print the value of as the eccentricity of the ellipse.
Below is the implementation of the above approach:
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 industry experts, please refer DSA Live Classes