×

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 conditional statements – Find output programs (set 3)

Last Updated : December 15, 2025

Program 1

num1 = 10;
num2 = 20;
num3 = 30;
large = 0;

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

print("Largest value is : ", large);

Output

Largest value is : 30

Explanation

In the above program, we created num1, num2, num3, large that are initialized with 10, 20, 30, 0 respectively. Then we found the largest number among 3 numbers using nested if and printed the largest number.


Program 2

num1 = -10;

if (num1 < 0) == true
  print("Number is NEGATIVE.");
else
  print("Number is POSITIVE.");
end

Output

Number is NEGATIVE.

Explanation

In the above program, we created a variable num1, which is initialized with -10. Then we checked num is POSITIVE or NEGATIVE using the if statement and printed the appropriate message.

Ruby Find Output Programs »



Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

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