This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-10-18 15:11:07

ProgrammingAddict
New Scratcher
Registered: 2011-08-23
Posts: 22

HCF and LCM

Is there a way to calculate the high common factor and lowest common mulitple in scratch. Say you had the number 6 and 10, how would I do it?

Offline

 

#2 2011-10-18 18:32:43

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: HCF and LCM

Well...you could have it run through numbers until it reaches half the highest number or the lower of the two numbers...so for that example it would look a little like:
HCF:
set [HCF] to 1
set [count] to 0
repeat until (count) > number1
    change [count] by (1)
    if round(number1/count)=number1/count and round(number2/count)=number2/count
        set [HCF] to (count)
    end
end
say join ("The highest common factor is ") (HCF)

LCM would take a bit more, but you could have it work backwards, starting at number1*number2 and working down by intervals of number1 or something.


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

Board footer