The gcdlcm()
integer method returns an array that has the greatest common divisor and the least common multiple of two integers, that is, [gcd, lcm]
.
int1.gcdlcm(int2)
int1
: This is the variable that has an integer value that invokes the gcdlcm()
method.int2
: This is the second variable that has an integer value. It is passed inside the gcdlcm()
method.The value returned is an array that contains the greatest common divisor and the least common multiple of int1
and int2
, that is, [gcd, lcm]
.
# create integer valuesint1 = 20int2 = 4int3 = 15int4 = 5# get greatest common divisor# and least common multipleputs "#{int1.gcdlcm(4)}" # 20 and 4 = [4,20]puts "#{int2.gcdlcm(2)}" # 4 and 2 = [2,4]puts "#{int3.gcdlcm(3)}" # 15 and 3 = [3,15]puts "#{int4.gcdlcm(100)}" # 5 and 100 = [5,100]
gcdlcm()
method to get the greatest common divisor and the least common multiple. Then, we print the results to the console.