×

Ruby Tutorial

Ruby Basics

Ruby Control Statements

Ruby Methods

Ruby Classes and Methods

Ruby Arrays

Ruby Sets

Ruby Strings

Ruby Classes & Objects

Ruby Hash

Ruby Tools

Ruby Functions

Ruby Built-in Functions

Misc.

Ruby Programs

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

Last Updated : December 15, 2025

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 »


Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

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