An algorithm is intended to display the names of planets in reverse order of their distance from the Sun, starting with the furthest ('Neptune') and ending with the closest ('Mercury').
The algorithm is represented below in pseudocode:
1 SUBROUTINE getPlanetName(planets)
planets ← ['Mercury', 'Venus', 'Earth', 'Mars',
2 'Jupiter', 'Saturn', 'Uranus', 'Neptune']
3 RETURN planets[p]
4 ENDSUBROUTINE
5
6 FOR i ← 8 TO 0 STEP 1
7 OUTPUT(getPlanetName(i))
8 ENDFOR
Rewrite line 1 and line 6 to make the algorithm work as intended.
Line 1:
Line 6:
131 exam-style questions on AQA GCSE Computer Science Structured programming and subroutines (procedures and functions). Each one has a worked solution and a mark scheme showing where the marks go.