Representing algorithms

EasyMediumHard
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
Question 9
Easy

An algorithm is designed to display a student's marks in four different school subjects. Each subject has two exam scores stored in a single list. The algorithm contains an error.

Figure 1 shows the pseudocode for this algorithm.

1  subjects ← ['Maths', 'English', 'Science', 'History']
2  grades ← [85, 90, 72, 78, 92, 88, 64, 70]
3  total ← 0
4  FOR i ← 0 TO 2
5      sub ← subjects[i]
6      OUTPUT 'Subject: ', sub
7      FOR j ← 0 TO 1
8          OUTPUT 'Exam: ', j + 1
9          mark ← grades[i * 2 + j]
10         OUTPUT mark
11         total ← total + mark
12     ENDFOR
13 ENDFOR

How could the error in the algorithm in Figure 1 be corrected?

Change line number 3 to: total←1\text{total} \leftarrow 1total←1

Change line number 4 to: FOR i←0 TO 3\text{FOR } i \leftarrow 0 \text{ TO } 3FOR i←0 TO 3

Change line number 7 to: FOR j←0 TO 2\text{FOR } j \leftarrow 0 \text{ TO } 2FOR j←0 TO 2

Change line number 9 to: mark←grades[j×4+i]\text{mark} \leftarrow \text{grades}[j \times 4 + i]mark←grades[j×4+i]

Representing algorithms Questions

  1. GCSE
  2. /Computer Science
  3. /Representing algorithms