📌  相关文章
📜  求给定两条边的直角三角形的斜边

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

求给定两条边的直角三角形的斜边

给定直角三角形的另外两条边,任务是找到它的斜边。
例子:

方法:毕达哥拉斯定理指出,直角三角形的斜边的平方等于其他两条边的平方和。
下面是上述方法的实现:

C++
// C++ implementation of the approach
#include
#include 
#include 
using namespace std;
 
// Function to return the hypotenuse of the
// right angled triangle
double findHypotenuse(double side1, double side2)
{
    double h = sqrt((side1 * side1) + (side2 * side2));
    return h;
}
 
// Driver code
int main()
{
    int side1 = 3, side2 = 4;
    cout << fixed << showpoint;
    cout << setprecision(2);
    cout << findHypotenuse(side1, side2);
}
     
// This code is contributed by
// Surendra_Gangwar


Java
// Java implementation of the approach
class GFG {
 
    // Function to return the hypotenuse of the
    // right angled triangle
    static double findHypotenuse(double side1, double side2)
    {
        double h = Math.sqrt((side1 * side1) + (side2 * side2));
        return h;
    }
 
    // Driver code
    public static void main(String s[])
    {
        int side1 = 3, side2 = 4;
        System.out.printf("%.2f", findHypotenuse(side1, side2));
    }
}


Python3
# Python implementation of the approach
 
# Function to return the hypotenuse of the
# right angled triangle
def findHypotenuse(side1, side2):
 
    h = (((side1 * side1) + (side2 * side2))**(1/2));
    return h;
 
# Driver code
side1 = 3;
side2 = 4;
 
print(findHypotenuse(side1, side2));
 
# This code contributed by Rajput-Ji


C#
// C# implementation of the approach
using System;
     
class GFG
{
 
    // Function to return the hypotenuse
    // of the right angled triangle
    static double findHypotenuse(double side1,
                                 double side2)
    {
        double h = Math.Sqrt((side1 * side1) +
                             (side2 * side2));
        return h;
    }
 
    // Driver code
    public static void Main()
    {
        int side1 = 3, side2 = 4;
        Console.Write("{0:F2}", findHypotenuse(side1,
                                               side2));
    }
}
 
// This code is contributed
// by Princi Singh


Javascript


输出:
5.00