QP School

Full Version: Greatest common divisor in Ruby
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.