Practice
ArraysCoreIGCSE 0478

Count positive values in an array

Array traversal practice: count how many stored integers are greater than zero.

An array Values stores 6 integers in positions 1 to 6.

Write pseudocode that counts how many of those values are greater than 0 and outputs the count.

Your program should

  • Declare Values as ARRAY[1:6] OF INTEGER.
  • You may assume the six values have already been stored.
  • Use a loop from 1 to 6.
  • Output the count of values greater than 0.

Sample input

—

Sample output

4

Starter

Pseudocode
// Count how many values in the array are greater than 0, then output the count.
DECLARE Values : ARRAY[1:6] OF INTEGER
DECLARE Index : INTEGER
DECLARE Count : INTEGER

Values[1] <- 4
Values[2] <- -1
Values[3] <- 0
Values[4] <- 18
Values[5] <- 3
Values[6] <- -7