Support Forums

Full Version: GCF Function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Code:
def highest_number(a)
    length = a.length
    great = a[0].to_i
    for i in 0..length do
        if a[i].to_i > great
            great = a[i]
        end
    end
    puts great
end

def gcf(a,b)
    array = []
    for i in 1..a do
        if a % i == 0 and b % i == 0
            array << i
        end
    end
    num = []
    num << highest_number(array)
    
    
end

#Example
gcf(12,20)
Nice code but basic :/ Thank you ;)