Structured programming and subroutines (procedures and functions)

EasyMediumHard
123456789101112131415161718192021222324252627282930313233343536373839404142
Question 42
Easy

Figure 3 shows a subroutine written in pseudocode that calculates the sum of all positive numbers in an array.

SUBROUTINE computeTotal(numbers)
  s ← 0
  i ← 0
  WHILE i < LENGTH(numbers)
    IF numbers[i] > 0 THEN
      s ← s + numbers[i]
    ENDIF
    i ← i + 1
  ENDWHILE
  RETURN s
ENDSUBROUTINE

The identifier for the variable s in Figure 3 was not a good choice.

State a better identifier for this variable that makes the algorithm easier to read and understand.

[1]

Structured programming and subroutines (procedures and functions) Questions

  1. GCSE
  2. /Computer Science
  3. /Structured programming and subroutines (procedures and functions)