Ruby Basic Exercises: Check a given non-negative number and return true if num is within 2 of a multiple of 10
Ruby Basic: Exercise-46 with Solution
Write a Ruby program to check a given non-negative number and return true if num is within 2 of a multiple of 10.
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)
true false true true true
Ruby Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Ruby program to check two given integers and return 11 if either one is 11. Return their sum or difference if sum or difference is 11.
Next: Write a Ruby program to check three given integers and return true if it is possible to add two of the integers to get the third.
What is the difficulty level of this exercise?
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework