Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

Ruby Basic Exercises: Check three given integers and return true if one of them is 20 or more less than one of the others

Ruby Basic: Exercise-49 with Solution

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.

Ruby Code:

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

Flowchart:

Flowchart: Check three given integers and return true if one of them is 20 or more less than one of the others

Ruby Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a Ruby program to check three given integers and return true if two or more of them have the same rightmost digit.
Next: Write a Ruby program to check two given integers and return the larger value. However if the two values have the same remainder when divided by 5 then return the smaller value and if the two values are the same, return 0.

What is the difficulty level of this exercise?