ADVERTISEMENT
ADVERTISEMENT

Ruby conditional statements – Find output programs (set 3)

This section contains the Ruby conditional statements find output programs (set 3) with their output and explanations.
Submitted by Nidhi, on February 11, 2022

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!



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.