Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GCF Function
#1
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)
Reply


Messages In This Thread
GCF Function - by nevets04 - 03-25-2010, 08:23 PM
RE: GCF Function - by HF~Legend - 12-03-2011, 02:32 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  isprime function nevets04 1 1,376 11-01-2010, 09:12 AM
Last Post: Arеs

Forum Jump:


Users browsing this thread: 2 Guest(s)