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.
Ruby Code:
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)
Output:
15 10
Flowchart:
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?
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/ruby-exercises/basic/ruby-basic-exercise-53.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics