Please refer to this page for information on how to work on your assignment.
Although historically Euclid's Algorithm was implemented by substracting the smaller number from the larger one, the famous version of the algorithm has one improvement: it computes the remainder of the division of two numbers instead of their difference. The task is to update the below program accordingly and to do some further changes of the input-output behaviour.
Test the currently implement algorithm with inputs 1000 and 2. Scroll down the window to inspect the output.
Read the program and understand what is going on. Then do the following changes:
x = x - y;and
y = y - x;in the source code.
xis different from
y. But since the remainder operation does not make
yequal, but one of them to 0, you have to check that both
yare greater than 0.
endtext. This test has to ask whether
x == 0or
y == 0but not whether
x == y.
endtextvariable plus a phrase which tells to click "OK" for continuing the program. So write something like:
do … while(confirm(endtext + " Press 'OK' to continue"));
Run the whole program and test it. Compare it on the inputs 1000 and 2 with the old program. Scroll down to check the protocol output printed during the computation. Is it faster than the old one?
You can hand in the program after checking its correctness by showing it to the lecturer.