Ruby program to find largest number from given 2 numbers


Following program shows you how to find largest number from given 2 numbers.
In this program we get inputs from user and shows largest number from given two numbers using if condition

 puts "Enter two numbers:"
 input1 = Integer(gets.chomp)
 input2 = Integer(gets.chomp)
 if input1 == input2
 puts "#{input1} is equal to #{input2}"
 elsif input1 > input2
 puts "#{input1} is larger than #{input2}"
 else
 puts "#{input1} is lesser than #{input2}"
 end

Output:

Example1:

Enter two numbers:
30
30
30 is equal to 30

Example2:

Enter two numbers:
50
10
50 is larger than 10

Example3:

Enter two numbers:
40
100
40 is lesser than 100