Ruby program to find the hypotenuse of a right-angled triangle with sides l and b

Ruby Example: Write a program to find the hypotenuse of a right-angled triangle with sides l and b.
Submitted by Nidhi, on December 07, 2021

Problem Solution:

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.

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.

# 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.

Ruby Basic Programs »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.