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.
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)
false true true
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?
- 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