w3resource

Ruby Basic Exercises: Find the maximum of two numbers


Write a Ruby program to find the maximum of two numbers.

Ruby Basic Exercises: Find the maximum of two numbers

Ruby Code:

x= 6
y =8
max = x>y ? x:y
puts "Max = "+max.to_s

Output:

Max = 8

Flowchart:

Flowchart: Find the maximum of two numbers

Go to:


PREV : Write a Ruby program to compute the absolute difference between n and 33 and return double the absolute difference if n is over 33.
NEXT : Write a Ruby program to check two integers and return true if one of them is 20 otherwise return their sum.

Ruby Code Editor:



Contribute your code and comments through Disqus.

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.