Ruby Basic Exercises: Check three given integers and return true if it is possible to add two of the integers to get the third
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.
Ruby Code:
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)
Output:
true true true false
Flowchart:
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?
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics