Ruby Basic Exercises: Check three given integers and return true if it is possible to add two of the integers to get the third
Ruby Basic: Exercise-47 with Solution
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.
def check_num(a, b, c) return ((a + b) == c || (b + c) == a || (c + a) == b) end print check_num(9, 12, 21),"\n" print check_num(0, -5, -5),"\n" print check_num(-5, 7, 2),"\n" print check_num(6, 5, 4)
true true true false
Ruby Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Ruby program to check a given non-negative number and return true if num is within 2 of a multiple of 10.
Next: Write a Ruby program to check three given integers and return true if two or more of them have the same rightmost digit.
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