VOOZH about

URL: https://www.geeksforgeeks.org/dsa/find-the-hypotenuse-of-a-right-angled-triangle-with-given-two-sides/

⇱ Find the hypotenuse of a right angled triangle with given two sides - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Find the hypotenuse of a right angled triangle with given two sides

Last Updated : 11 Jul, 2025

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:


Output
5.00

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)

Comment
Article Tags:
Article Tags: