The remainder() is an inbuilt method in Ruby returns the remainder when num1 is divided by num2.
Syntax: num1.remainder(num2)
Parameters: The function needs num1 and num2 which are to be divided.
Return Value: It returns the remainder.
Example 1:
# Ruby program for remainder() # method in Numeric # Initialize a number num1 = 17
num2 = 4
# Prints the remainder part puts num1.remainder(num2) |
Output:
1
Example 2:
# Ruby program for remainder() # method in Numeric # Initialize a number num1 = 12
num2 = 5
# Prints the remainder part puts num1.remainder(num2) |
Output:
2