Ruby program to find largest number from given 3 numbers
Following program shows you how to find largest number from given 3 numbers.
In this program we get inputs from user and shows largest number from given three numbers using if condition
puts "Enter three numbers:"
input1 = Integer(gets.chomp)
input2 = Integer(gets.chomp)
input3 = Integer(gets.chomp)
if (input1 == input2) && (input1 == input3)
puts "All numbers are equal"
elsif (input1 > input2) && (input1 > input3)
puts "#{input1} is larger than #{input2} and #{input3}"
elsif (input2 > input1) && (input2 > input3)
puts "#{input2} is larger than #{input1} and #{input3}"
elsif (input3 > input1) && (input3 > input2)
puts "#{input3} is larger than #{input2} and #{input1}"
end
Output:
Example1:
Enter three numbers:
60
30
10
60 is larger than 30 and 10
Example2:
Enter three numbers:
20
20
20
All numbers are equal