Ruby Basic Exercises: Check two integer values
Ruby Basic: Exercise-8 with Solution
Write a Ruby program to check two integer values whether either of them is in the range 20..30 inclusive.
Ruby Code:
def in2030(a, b)
return ((a >= 20 && a <= 30) || (b >= 20 && b <= 30));
end
print in2030(15, 99),"\n"
print in2030(25, 28),"\n"
Output:
false true
Flowchart:
Ruby Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Ruby program to accept a filename from the user print the extension of that.
Next: 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.
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-8.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics