Ruby Integer divmod() function with example
Last Updated :
24 Jun, 2020
Improve
The divmod() function in Ruby returns integer division value and the remainder.
Ruby
Output:
Ruby
Output:
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)
3 3 5 0Example #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)
9 1 2 2