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
#2
Nice code but basic :/ Thank you ;)
[Image: BKlNU.png]

---------
Reply


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

Forum Jump:


Users browsing this thread: 1 Guest(s)