In this program, we will read the sides L and B from the user. Then we will find the hypotenuse of a right-angled triangle using the Math.hypot() function.
The source code to find the hypotenuse of a right-angled triangle with sides l and b is given below. The given program is compiled and executed successfully.
# Ruby program to find the hypotenuse of a
# right-angled triangle with sides l and b
print "Enter side L: ";
l = gets.chomp.to_i;
print "Enter side B: ";
b = gets.chomp.to_i;
result = Math.hypot(l, b);
print "Result: ",result;
Output:
Enter side L: 23
Enter side B: 24
Result: 33.24154027718932
Explanation:
In the above program, we read sides L and B of right-angled triangle from the user and found the hypotenuse of using Math.hypot() function, and printed the result.
Program/Source Code:
The source code to find the hypotenuse of a right-angled triangle with sides l and b is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we read sides L and B of right-angled triangle from the user and found the hypotenuse of using Math.hypot() function, and printed the result.
need an explanation for this answer? contact us directly to get an explanation for this answer