Ruby Basic Exercises: Check three given integers and compute their sum
Ruby Basic: Exercise-53 with Solution
Write a Ruby program to check three given integers and compute their sum. However, if one of the values is 17 then it does not count towards the sum and values to its right do not count.
def check_num(a, b, c) if a==13 retunr 0 elsif b ==17 return a elsif c == 17 return a + b else a + b + c end end print check_num(5, 5, 5),"\n" print check_num(5, 5, 17)
Ruby Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Ruby program to check three given integers and return their sum. However, If one of the values is the same as another of the values, it does not count towards the sum.
Next: Write a Ruby program to check three given integers x, y, z and return true if one of y or z is close (differing from a by at most 1), while the other is far, differing from both other values by 3 or more.
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