Ruby Integer remainder() function with example
The remainder() function in Ruby returns the remainder when two numbers are divided.
Syntax: (number1).remainder(number2)
Parameter: The function takes two number number1 and number2 whose integer division and remainder is returned.
Return Value: The function returns the remainder.
Example 1:
Ruby
# Ruby program for remainder() function # Initializing the numbersnum1 = 18num2 = 3num3 = 13num4 = 5 # Printing the modulo valueputs num1.remainder(num2)puts num3.remainder(num4) |
Output:
0 3
Example 2:
Ruby
# Ruby program for remainder() function # Initializing the numbersnum1 = 19num2 = 4num3 = 20num4 = 5 # Printing the modulo valueputs num1.remainder(num2)puts num3.remainder(num4) |
Output:
3 0



