ADVERTISEMENT
ADVERTISEMENT

Ruby program to demonstrate the nested if statement

Ruby Example: Write a program to demonstrate the nested if statement.
Submitted by Nidhi, on December 17, 2021

Problem Solution:

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

Program/Source Code:

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

# Ruby program to demonstrate 
# the nested 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)
    if(num1>num3)
        large=num1;
    else
        large=num3;
    end
elsif(num2>num3)
    large=num2;
else
    large=num3;
end

print "Largest number is: ",large;

Output:

Enter number1: 23
Enter number2: 10
Enter number3: 46
Largest number is: 46

Explanation:

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

Ruby if/else Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.