The following pseudocode calculates and outputs two values k and j. It then calculates and outputs to further values t and a.
x = [7, 9, 6, 2, 4]
t = x[1]
k = x[1]
j = x[1]
FOR n = 2 TO 5
t = t + x[n]
IF x[n] > k THEN
k = x[n]
ENDIF
IF x[n] <j THEN
j = x[n]
NEXT n
OUTPUT (“k = ”, k, (“j = ”,j)
t = t – k – j
a = t/3
a = int(a)
OUTPUT (“a = ”,a)
what does x[1] mean? at first I thought it meant that the variable (eg: t) was = to the 1st argument of the array x. But then I realised that then t, k, and j would all have the same values...
The [1]
is the index of the x
array. In this case, x[1]
has a value of 9
.