02-28-2021, 09:09 AM
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.
This will print 12 on the screen.
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.