📜  求椭圆直肠长度的程序

📅  最后修改于: 2021-10-23 08:26:30             🧑  作者: Mango

给定两个整数AB,用一般方程(x 2 / A 2 ) + (y 2 / B 2 ) = 1表示椭圆的长半轴和半短轴的长度,任务是找到长度椭圆的直肠阔肌

例子:

方法:根据以下观察可以解决给定的问题:

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

  • 初始化两个变量,说主要次要,以分别存储长轴(= 2A)和短轴(= 2B)椭圆的长度的长度。
  • 计算小调的平方 并将其与专业分开。将结果存储在一个双变量中,比如latus_rectum
  • 打印latus_rectum的值作为最终结果。  

下面是上述方法的实现:

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


输出:
2.66667

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

如果您希望与专家一起参加现场课程,请参阅DSA 现场工作专业课程学生竞争性编程现场课程