Ruby Basic Exercises: Check two non-negative integer values and return true if they have the same last digit
Ruby Basic: Exercise-30 with Solution
Write a Ruby program to check two non-negative integer values and return true if they have the same last digit.
Sample array : ["Ruby", 2.3, Time.now]
Ruby Code:
def test_last_digit(a, b)
return (a % 10 == b % 10);
end
print test_last_digit(5, 5),"\n"
print test_last_digit(15, 25),"\n"
print test_last_digit(256, 346),"\n"
print test_last_digit(26, 34)
Output:
true true true false
Flowchart:
Ruby Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Ruby program to print the elements of a given array.
Next: Write a Ruby program to retrieve the total marks where subject name and marks of a student stored in a hash.
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-30.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics