Q:

Write a Ruby program to check a given non-negative number and return true if number is within 2 of a multiple of 10

0

 Write a Ruby program to check a given non-negative number and return true if number is within 2 of a multiple of 10.

All Answers

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

def check_num(num)
   return num % 10 <= 2 || num % 10 >= 8;
end
print check_num(9),"\n"
print check_num(13),"\n"
print check_num(22),"\n"
print check_num(-12),"\n"
print check_num(0)

Output:

true
false
true
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