Ruby Integer divmod() function with example
The divmod() function in Ruby returns integer division value and the remainder.
Syntax: (number1).divmod(number2)
Parameter: The function takes two number number1 and number2 whose integer division and remainder is returned.
Return Value: The function returns the integer division value and the remainder.
Example #1:
# Ruby program of Integer divmod() function # Initializing the numbers num1 = 15 num2 = 4 num3 = 10 num4 = 2 # Prints the integer division # and its remainder puts num1.divmod(num2) puts puts num3.divmod(num4) |
Output:
3 3 5 0
Example #2:
# Ruby program of Integer divmod() function # Initializing the numbers num1 = 19 num2 = 2 num3 = 28 num4 = 13 # Prints the integer division # and its remainder puts num1.divmod(num2) puts puts num3.divmod(num4) |
Output:
9 1 2 2