Poll: Was this article helpful for you?
You do not have permission to vote in this poll.
Yes
100.00%
1 100.00%
No
0%
0 0%
Total 1 vote(s) 100%
* You voted for this item. [Show Results]

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Greatest common divisor and least common multiple in Ruby
#1
To get the greatest common divisor and the least common multiple of 2 numbers at the same time 
we can use the gcd_lcm function instead of gcd and lcm in two separated functions.
In this example we want to know the greatest common divisor 
and the least common multiple of 36 and 60.


Quote:num1 = 36
num2 = 60
gcd_lcm = num1.gcd_lcm(num2)

puts gcd_lcm


This will print 12 and 180 in two lines on the screen.
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
Reply


Messages In This Thread
Greatest common divisor and least common multiple in Ruby - by Qomplainerz - 02-28-2021, 09:13 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Everything you need to know about Ruby Qomplainerz 0 565 07-25-2023, 09:53 AM
Last Post: Qomplainerz
  Additions in Ruby Qomplainerz 0 1,586 03-14-2021, 10:13 AM
Last Post: Qomplainerz
  Subtractions in Ruby Qomplainerz 0 1,508 03-08-2021, 11:42 AM
Last Post: Qomplainerz
  Predecessor in Ruby Qomplainerz 0 1,607 02-28-2021, 10:31 AM
Last Post: Qomplainerz
  Successor in Ruby Qomplainerz 0 1,551 02-28-2021, 10:29 AM
Last Post: Qomplainerz
  Least common multiple in Ruby Qomplainerz 0 1,648 02-28-2021, 09:11 AM
Last Post: Qomplainerz
  Greatest common divisor in Ruby Qomplainerz 0 1,596 02-28-2021, 09:09 AM
Last Post: Qomplainerz
  Floor and precisions in Ruby Qomplainerz 0 1,613 02-28-2021, 08:40 AM
Last Post: Qomplainerz
  Ceil and precisions in Ruby Qomplainerz 0 1,623 02-28-2021, 08:35 AM
Last Post: Qomplainerz
  Quotients and remainders in Ruby Qomplainerz 0 1,850 02-27-2021, 08:51 AM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 2 Guest(s)