Ruby 整数 lcm()函数与示例
Ruby 中的lcm()函数返回两个数字的 lcm。 LCM 表示可被两个数字整除的最小公倍数。
Syntax: number1.lcm(number2)
Parameter: The function requires two numbers whose lcm is returned.
Return Value: The function returns the lcm of two numbers
示例 #1:
# Ruby program of Integer lcm() function
# Initializing the numbers
num1 = 10
num2 = 15
num3 = 21
num4 = 14
# Prints the lcm value
puts num1.lcm(num2)
puts num3.lcm(num4)
输出:
30
42
示例 #2:
# Ruby program of Integer lcm() function
# Initializing the numbers
num1 = 22
num2 = 18
num3 = 30
num4 = 25
# Prints the lcm value
puts num1.lcm(num2)
puts num3.lcm(num4)
输出:
198
150