×

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 demonstrate the ladder if statement

Last Updated : December 15, 2025

Problem Solution

In this program, we will demonstrate the ladder if statement. Here we will read three integer numbers from the user and find the largest number among them using the ladder if statement.

Program/Source Code

The source code to demonstrate the ladder if statement is given below. The given program is compiled and executed successfully.

# Ruby program to demonstrate 
# the ladder if statement

print "Enter number1: ";
num1 = gets.chomp.to_i;  

print "Enter number2: ";
num2 = gets.chomp.to_i;  

print "Enter number3: ";
num3 = gets.chomp.to_i;  

if(num1>num2 && num1>num3)
    large=num1;
elsif(num2>num1 && num2>num3)
    large=num2;
else
    large=num3;
end

print "Largest number is: ",large;

Output

Enter number1: 23
Enter number2: 25
Enter number3: 15
Largest number is: 25

Explanation

In the above program, we read three integer numbers from the user and found the largest number among them using the ladder if statement and printed the result.

Ruby if/else Programs »


Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

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