Ruby Integer modulo()函数与示例
Ruby 中的模函数返回一个数字与另一个数字的模值。
Syntax: number1.modulo(number2)
Parameter: The function takes number1 and number2 whose modulo is returned.
Return Value: The function returns the modulo value of a number by another number.
示例 #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