This text was translated automatically and has not been checked by a native speaker yet. If you spot a mistake, please let us know.
Mathematics 10 · Grade 10
2.8. Algorithms Tasks from the two previous sections are mixed in for review.
Printable worksheet
Turn on JavaScript to use the trainer. The rule and worked examples are available without it.
Rule and examples Algorithms: step-by-step execution Run an algorithm step by step, writing down the values of the variables. A “while” loop repeats as long as its condition is true; at a branch, check the condition first. In Euclid’s algorithm, divide a by b with remainder until the remainder is 0.
Example 1. Run the algorithm. What number does it output? 1. a = 46, b = 16 2. If a is even, then c = a : 2; otherwise c = a + b. 3. Output c.
Here a = 46, b = 16: the condition “a is even” is true. c = a : 2 = 23 Answer: 23
Example 2. Run the algorithm. What number does it output? 1. x = 4 2. If x < 84, go to step 3; otherwise go to step 4. 3. x = 3 · x; go back to step 2. 4. Output x.
x: 4 → 12 → 36 → 108 108 ≥ 84 — the loop stops after 3 repetitions. Answer: 108
Example 3. Run the algorithm. What number does it output? 1. a = 49, b = 14 2. If b = 0, go to step 4. 3. r is the remainder of a divided by b; a = b, b = r; go back to step 2. 4. Output a.
49 = 14 · 3 + 7 14 = 7 · 2 + 0 GCD(49, 14) = 7 Answer: 7