Ruby Basic Exercises: Check whether a number is within 10 of 100 or 200
Ruby Basic: Exercise-21 with Solution
Write a Ruby program to check whether a number is within 10 of 100 or 200.
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)
false true true
Ruby Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Ruby program to find the greatest of three numbers.
Next: Write a Ruby program to compute the sum of the two integers, if the two values are equal return double their sum otherwise return their sum.
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