QP School
Greatest common divisor and least common multiple in Ruby - Printable Version

+- QP School (https://qomplainerzschool.lima-city.de)
+-- Forum: Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=3)
+--- Forum: Ruby 3 Tutorials, exercises and examples (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=17)
+--- Thread: Greatest common divisor and least common multiple in Ruby (/showthread.php?tid=2506)



Greatest common divisor and least common multiple in Ruby - Qomplainerz - 02-28-2021

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.