📜  计算双曲线直肠直肠长度的程序

📅  最后修改于: 2022-05-13 01:56:10.190000             🧑  作者: Mango

计算双曲线直肠直肠长度的程序

给定两个整数AB ,表示双曲线的半长轴和半短轴的长度,任务是找到双曲线的直角长度。

例子:

方法:双曲线的直角是垂直于长轴的焦弦,直肠的长度等于(短轴的长度) 2 /(长轴的长度)。

请按照以下步骤解决给定的问题:

  • 找到双曲线长轴的长度并将其存储在一个变量中,比如major
  • 找到双曲线短轴的长度并将其存储在一个变量中,比如minor
  • 完成上述步骤后,打印(minor*minor)/major的值作为 Latus Rectum 的合成长度。

下面是上述方法的实现:

C++
// C++ program for the above approach
 
#include 
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


输出:
2.66667

时间复杂度: O(1)
辅助空间: O(1)