Note AcademyNote Academy

Computer Science · Oct / Nov 2021 · Paper 21 · Question 2

0478

As printed in the paper

The question as text

An algorithm has been written in pseudocode to generate 50 positive random integers with values less than or equal to 100. These random integers are stored in the array RandNum[ ] The function Rand(X, Y) generates a random integer greater than or equal to X and less than Y. For example, Rand(1, 4) generates 1 or 2 or 3. 1 Count 0 2 REPEAT 3 RandNum[Counter] Rand(1, 100) 4 Count Count + 2 5 UNTIL Count <= 50

Read automatically from the paper; the printed page above is exact.

Show the answer and mark scheme
  • 2(a)[4]

    Line 1 should be Counter ← 0

    Line 3 RandNum[Counter] ← Rand(1, 100)should be RandNum[Counter] ← Rand(1, 101)

    Line 4 Counter ← Counter + 2 should be Counter ← Counter + 1

    Line 5 UNTIL Count <= 50 should be UNTIL Counter >= 50 // UNTIL Counter = 50

    1

    Counter ← 0

    2

    REPEAT

    3

    RandNum[Counter} ← Rand(1, 100)

    4

    Counter ← Counter + 1

    5

    UNTIL Counter >= 50

    Or

    Line 3 RandNum[Counter] should be RandNum[Count]

    Line 3 Rand(1, 100)should be Rand(1, 101)

    Line 4 Counter ← Counter + 2 should be Count ← Count + 1

    Line 5 UNTIL Count <= 50 should be UNTIL Count >= 50 // UNTIL Count = 50

    1

    Count ← 0

    2

    REPEAT

    3

    RandNum[Count} ← Rand(1, 100)

    4

    Count ← Count + 1

    5

    UNTIL Count >= 50

  • 2(b)[3]

    One mark for each correct line

    FOR Count ← 0 TO 49 // FOR Count ← 1 TO 50

    RandNum[Count] ← Rand(1, 101) / Rand(0, 101)

    NEXT // NEXT Count

  • 2(c)[1]

    Precondition loop // WHILE … DO … ENDWHILE

Make a free account to save your answers and see your weak topics and ask the AI why a wrong answer is wrong.