红宝石 |数值余数()函数
当 num1 除以 num2 时, remainder()是 Ruby 中的一个内置方法返回余数。
Syntax: num1.remainder(num2)
Parameters: The function needs num1 and num2 which are to be divided.
Return Value: It returns the remainder.
示例 1 :
# Ruby program for remainder()
# method in Numeric
# Initialize a number
num1 = 17
num2 = 4
# Prints the remainder part
puts num1.remainder(num2)
输出:
1
示例 2 :
# Ruby program for remainder()
# method in Numeric
# Initialize a number
num1 = 12
num2 = 5
# Prints the remainder part
puts num1.remainder(num2)
输出:
2