The modulo function in Ruby returns the modulo value of a number by another number.
Syntax: number1.modulo(number2)
Parameter: The function takes number1 and number2 whose modulo is returned.
Return Value: The function returns the modulo value of a number by another number.
Example #1:
Ruby
# Ruby program of modulo function # Initializing the numbers num1 = 10
num2 = 6
num3 = 13
num4 = 5
# Printing the modulo value puts num1.modulo(num2) puts num3.modulo(num4) |
Output:
4 3
Example #2:
Ruby
# Ruby program of modulo function # Initializing the numbers num1 = 100
num2 = 17
num3 = 90
num4 = 29
# Printing the modulo value puts num1.modulo(num2) puts num3.modulo(num4) |
Output:
15 3