Repeating algorithms
Answers are for parents and teachers.
1
Write in words (briefly) the calculation of the sum of numbers from 1 to 100 with three kinds of loop.
Parameter: S = 0; i from 1 to 100: S = S + i. While: i = 1; while i ≤ 100: S = S + i, i = i + 1. Until: i = 1; repeat S = S + i, i = i + 1 until i > 100. Answer 5050.
2
S = 0; for i = 2, 4, 6, 8 do S = S + i. What is S?
20
3
P = 1; for i from 2 to 6 do P = P · i. What is P?
720
4
Find the sum of the multiples of 6 from 1 to 30.
90
5
Calculate y = x³ – 2x for x = 3.
21