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
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.
Offline