Q:

Write a Ruby program to check two integers and return whichever value is nearest to the value 10

0

Write a Ruby program to check two integers and return whichever value is nearest to the value 10, or return 0 if two integers are equal.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

def text_int(a, b)
    ma = (10-a).abs;
	mb = (10-b).abs;
	if (ma < mb)
		return a;
	end
	if (mb < ma)
		return b;
	end
	return 0;
end
print text_int(7, 14),"\n"
print text_int(6, 9),"\n"
print text_int(5, 5)
Output:
7
9
0

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now