QP School
Greatest common divisor 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 in Ruby (/showthread.php?tid=2504)



Greatest common divisor in Ruby - Qomplainerz - 02-28-2021

To get the greatest common divisor of 2 numbers we can use the gcd function.
In this example we want to know the greatest common divisor of 36 and 60.


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

puts gcd


This will print 12 on the screen.