Q:

Write a Ruby program to check whether a number is within 10 of 100 or 200

0

Write a Ruby program to check whether a number is within 10 of 100 or 200

All Answers

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

def near_hundred(n)
    (n-100).abs <= 10 || (n-200).abs <= 10
end

print near_hundred(10),"\n" 
print near_hundred(110),"\n" 
print near_hundred(90)
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