Skip to content
Related Articles

Related Articles

Improve Article

Ruby Integer lcm() function with example

  • Last Updated : 07 Jan, 2020

The lcm() function in Ruby returns the lcm of two numbers. LCM signifies the lowest common multiple which is divisible by both the numbers.

Syntax: number1.lcm(number2)

Parameter: The function requires two numbers whose lcm is returned.

Return Value: The function returns the lcm of two numbers

Example #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)  

Output:

30
42

Example #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) 

Output:

198
150
My Personal Notes arrow_drop_up
Recommended Articles
Page :