📜  Ruby整数剩余()函数与示例

📅  最后修改于: 2022-05-13 01:54:31.704000             🧑  作者: Mango

Ruby整数剩余()函数与示例

Ruby 中的剩余()函数返回两个数字相除时的余数。

示例 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