How to find the hypotenuse of a right angle triangle

View Discussion

Improve Article

Save Article

  • Read
  • Discuss
  • View Discussion

    Improve Article

    Save Article

    Given the other two sides of a right angled triangle, the task is to find it’s hypotenuse.
    Examples: 
     

    Input: side1 = 3, side2 = 4 
    Output: 5.00 
    32 + 42 = 52
    Input: side1 = 12, side2 = 15 
    Output: 19.21 
     

    Approach: Pythagoras theorem states that the square of hypotenuse of a right angled triangle is equal to the sum of squares of the other two sides.
    Below is the implementation of the above approach:
     

    C++

    #include<bits/stdc++.h>

    #include <iostream>

    #include <iomanip>

    using namespace std;

    double findHypotenuse(double side1, double side2)

    {

        double h = sqrt((side1 * side1) + (side2 * side2));

        return h;

    }

    int main()

    {

        int side1 = 3, side2 = 4;

        cout << fixed << showpoint;

        cout << setprecision(2);

        cout << findHypotenuse(side1, side2);

    }

    Java

    class GFG {

        static double findHypotenuse(double side1, double side2)

        {

            double h = Math.sqrt((side1 * side1) + (side2 * side2));

            return h;

        }

        public static void main(String s[])

        {

            int side1 = 3, side2 = 4;

            System.out.printf("%.2f", findHypotenuse(side1, side2));

        }

    }

    Python3

    def findHypotenuse(side1, side2):

        h = (((side1 * side1) + (side2 * side2))**(1/2));

        return h;

    side1 = 3;

    side2 = 4;

    print(findHypotenuse(side1, side2));

    C#

    using System;

    class GFG

    {

        static double findHypotenuse(double side1,

                                     double side2)

        {

            double h = Math.Sqrt((side1 * side1) +

                                 (side2 * side2));

            return h;

        }

        public static void Main()

        {

            int side1 = 3, side2 = 4;

            Console.Write("{0:F2}", findHypotenuse(side1,

                                                   side2));

        }

    }

    Javascript

    <script>

    function findHypotenuse(side1, side2){

        let h = (((side1 * side1) + (side2 * side2))**(1/2));

        return h;

    }

    let side1 = 3;

    let side2 = 4;

    document.write(findHypotenuse(side1, side2).toFixed(2));

    </script>

    Time Complexity: O(log(2*(s2)) where s is the side of the rectangle. because time complexity of inbuilt sqrt function is O(log(n))

    Auxiliary Space: O(1)


    How do you find the hypotenuse of a triangle with angles?

    If you have an angle and the side opposite to it, you can divide the side length by sin(θ) to get the hypotenuse. Alternatively, divide the length by tan(θ) to get the length of the side adjacent to the angle.

    What is hypotenuse in right angle triangle?

    The hypotenuse of a right triangle is always the side opposite the right angle. It is the longest side in a right triangle.

    How do you find the hypotenuse of a right triangle Grade 8?

    In order to calculate hypotenuse of a triangle, we usually use the Pythagoras Theorem. According to this theorem, The sum of the square of two sides i.e. the base and the perpendicular side of any right angled triangle is equal to the square of the longest side, i.e. the hypotenuse.

    What is formula for right angle triangle?

    Area of Right Angle Triangle = ½ (Base × Perpendicular) If one of the angles is 90° and the other two angles are equal to 45° each, then the triangle is called an Isosceles Right Angled Triangle, where the adjacent sides to 90° are equal in length.

    Toplist

    Latest post

    TAGs