Hello
Beginner Scratch user here.
I am trying to write a script calculating the GCF using the Euclidean Algorithm.
I want to use the mod block in my script.
For example: I want to find the GCF between 24 and 10.
The script would calculate 24 mod 10 which is 4.
Then calculate 10 mod 4 which is 2
Then calculate 4 mod 2 which is 0 so my GCF would be 2.
I have set up variables divisor, dividend, remainder and answer in my script but having trouble getting it to work. I would like the GCF to be displayed an the answer.
I have uploaded my beginning project on my page under Transformed71506.
Any help would greatly be appreciated! Thanks!
Offline
What you could d is enter each item on a list (i.e. delete all of the list, then add each new number you are dividing by). Set up the script to repeat until the last item of the list is zero, then have it set a variable to the second to last number, which will be your GCF. Does this work for you?
EDIT: One other thing, I saw on your project you were trying to use the "answer" block, but you can't set that to just anything, it's there for raw input when the "ask" block is used.
Last edited by AtomicBawm3 (2010-11-29 07:36:25)
Offline
Try this:
I made it in a few minutes.
http://scratch.mit.edu/projects/12three/1448919
Offline
Thanks AtomicBawm3 and12three for your help!
It works great and I see my mistakes!
Offline
Transformed71506 wrote:
Thanks AtomicBawm3 and12three for your help!
It works great and I see my mistakes!
Yep.
Offline