📜  Ruby Integer modulo()函数与示例

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

Ruby Integer modulo()函数与示例

Ruby 中的函数返回一个数字与另一个数字的模值。

示例 #1:

Ruby
# Ruby program of modulo function
 
# Initializing the numbers
num1 = 10
num2 = 6
num3 = 13
num4 = 5
      
# Printing the modulo value
puts num1.modulo(num2)
puts num3.modulo(num4)


Ruby
# Ruby program of modulo function
 
# Initializing the numbers
num1 = 100
num2 = 17
num3 = 90
num4 = 29
     
# Printing the modulo value
puts num1.modulo(num2)
puts num3.modulo(num4)


输出

4
3

示例 #2:

红宝石

# Ruby program of modulo function
 
# Initializing the numbers
num1 = 100
num2 = 17
num3 = 90
num4 = 29
     
# Printing the modulo value
puts num1.modulo(num2)
puts num3.modulo(num4)

输出

15
3