w3resource

Ruby Basic Exercises: Find the greatest of three numbers

Ruby Basic: Exercise-20 with Solution

Write a Ruby program to find the greatest of three numbers.

Ruby Basic Exercises: Find the greatest of three numbers

Ruby Code:

x,y,z = 2,5,4
if x >= y and x >= z
     puts "x = #{x} is greatest."
elsif y >= z and y >= x 
     puts "y = #{y} is greatest."
else 
     puts "z = #{z} is greatest."
end

Output:

y = 5 is greatest.

Flowchart:

Flowchart: Find the greatest of three numbers

Ruby Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a Ruby program to check two integers and return true if one of them is 20 otherwise return their sum.
Next: Write a Ruby program to check if a number is within 10 of 100 or 200.

What is the difficulty level of this exercise?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/ruby-exercises/basic/ruby-basic-exercise-20.php