Write a program to find the hypotenuse H of a right-angled triangle of sides A and B.
Note: Pythagoras theorem states that, for a right-angled triangle. Hypotenuse2 = A2 + B2
Input
The first line is an integer, A.
The second line is an integer, B.
Output
The output should be an integer.
Explanation
In the given example, the first side A = 3, and the second side B = 4. To calculate the hypotenuse we use Pythagoras theorem.
According to Pythagoras theorem, hypotenuse2 = 32 + 42
Therefore, the hypotenuse value is 5.
So, the output should be 5.
Sample Input 1
3
4
Sample Output 1
5
Sample Input 2
12
5
Sample Output 2
13
def hypotenuse(s1, s2):
hypo = (((s1 * s1) + (s2 * s2))**(1/2));
return hypo;
print("Sample Input 1")
print(3)
print(4)
print("Sample output 1")
print(hypotenuse(3, 4));
print("\n")
print("Sample Input 2")
print(12)
print(5)
print("Sample output 2")
print(hypotenuse(5, 12));
Comments
Leave a comment