Ruby整数剩余()函数与示例
Ruby 中的剩余()函数返回两个数字相除时的余数。
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.
示例 1 :
Ruby
# Ruby program for remainder() function
# Initializing the numbers
num1 = 18
num2 = 3
num3 = 13
num4 = 5
# Printing the modulo value
puts num1.remainder(num2)
puts num3.remainder(num4)
Ruby
# Ruby program for remainder() function
# Initializing the numbers
num1 = 19
num2 = 4
num3 = 20
num4 = 5
# Printing the modulo value
puts num1.remainder(num2)
puts num3.remainder(num4)
输出:
0
3
示例 2 :
红宝石
# Ruby program for remainder() function
# Initializing the numbers
num1 = 19
num2 = 4
num3 = 20
num4 = 5
# Printing the modulo value
puts num1.remainder(num2)
puts num3.remainder(num4)
输出:
3
0