Ruby Basic Exercises: Check three numbers into the range
Ruby Basic: Exercise-10 with Solution
10. Write a Ruby program to check three numbers and return true if one or the other is small, but not both. A number is called "small" if it is in the range 1..10 inclusive.
Ruby Code:
def in110(a, b)
return (((a >= 1 && a <= 10) && !(b >= 1 && b <= 10)) ||
(!(a >= 1 && a <= 10) && (b >= 1 && b <= 10)));
end
print in110(1, 12),"\n"
print in110(10, 15),"\n"
print in110(11, 25),"\n"
Output:
true true false
Flowchart:
Ruby Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Ruby program to check three numbers and return true if one or more of them are small. A number is called "small" if it is in the range 1..10 inclusive.
Next:Write a Ruby program to print the following 'here document'.
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-10.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics