Support Forums
GCF Function - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Ruby and Ruby on Rails (https://www.supportforums.net/forumdisplay.php?fid=55)
+---- Thread: GCF Function (/showthread.php?tid=5391)



GCF Function - nevets04 - 03-25-2010

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)



RE: GCF Function - HF~Legend - 12-03-2011

Nice code but basic :/ Thank you ;)