Q:

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

0

 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.

All Answers

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

def check_num(a, b, c)
    return ((a - b).abs >= 20 || (b - c).abs >= 20 || (c - a).abs >= 20)
end

print check_num(9, 12, 22),"\n"
print check_num(112, 202, 20),"\n"
print check_num(102, 203, 405)
Output:
false
true
true

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