Ruby Integer divmod() function with example
Last Updated :
24 Jun, 2020
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:
num1 = 15
num2 = 4
num3 = 10
num4 = 2
puts num1.divmod(num2)
puts
puts num3.divmod(num4)
|
Output:
3
3
5
0
Example #2:
num1 = 19
num2 = 2
num3 = 28
num4 = 13
puts num1.divmod(num2)
puts
puts num3.divmod(num4)
|
Output:
9
1
2
2
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...