w3resource

Ruby Basic Exercises: Check three given integers and return true if two or more of them have the same rightmost digit

Ruby Basic: Exercise-48 with Solution

Write a Ruby program to check three given integers and return true if two or more of them have the same rightmost digit.

Ruby Code:

def check_num(a, b, c)
    x = a % 10
	y = b % 10
	z = c % 10
	if(x == y)
		return true
	end	
	if(x == z)
		return true
	end
	return (y == z)
end
print check_num(9, 12, 22),"\n"
print check_num(112, 202, 52),"\n"
print check_num(102, 203, 405)

Output:

true
true
false

Flowchart:

Flowchart: Check three given integers and return true if two or more of them have the same rightmost digit

Ruby Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a Ruby program to check three given integers and return true if it is possible to add two of the integers to get the third.
Next: Write a Ruby program to check three given integers and return true if one of them is 20 or more less than one of the others.

What is the difficulty level of this exercise?