WDTPD - Arrays

12 questions

Q1
What is the output?
A = [4, 7, 2, 9, 1]
FOR i = 0 TO 3
    IF A[i] > A[i+1] THEN
        temp = A[i]
        A[i] = A[i+1]
        A[i+1] = temp
    END IF
NEXT i
OUTPUT A[4]
Q2
What is the output?
A = [2, 4, 6, 8, 10]
FOR i = 0 TO 4
    A[i] = A[i] / 2
NEXT i
OUTPUT A[0] + A[2] + A[4]
Q3
What is the output?
A = [1, 2, 3, 4, 5]
B = [0, 0, 0, 0, 0]
FOR i = 0 TO 4
    B[4-i] = A[i]
NEXT i
OUTPUT B[1] + B[3]
Q4
What is the output?
A = [7, 3, 9, 1, 5]
min_idx = 0
FOR i = 1 TO 4
    IF A[i] < A[min_idx] THEN
        min_idx = i
    END IF
NEXT i
OUTPUT min_idx
Q5
What is the output?
A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
s = 0
FOR i = 0 TO 2
    s = s + A[i][2-i]
NEXT i
OUTPUT s
Q6
What is the output?
A = [3, 1, 4, 1, 5, 9]
s = 0
FOR i = 0 TO 5
    IF A[i] > 3 THEN
        s = s + A[i]
    END IF
NEXT i
OUTPUT s
Q7
What is the output?
A = [3, 0, 2, 1]
OUTPUT A[A[A[0]]]
Q8
What is the output?
A = [1, 1, 2, 3, 5, 8]
s = 0
FOR i = 2 TO 5
    IF A[i] == A[i-1] + A[i-2] THEN
        s = s + 1
    END IF
NEXT i
OUTPUT s
Q9
What is the output?
A = [5, 3, 8, 1, 4]
count = 0
FOR i = 0 TO 3
    FOR j = i+1 TO 4
        IF A[i] > A[j] THEN
            count = count + 1
        END IF
    NEXT j
NEXT i
OUTPUT count
Q10
What is the output?
A = [1, 2, 3, 4, 5]
FOR i = 0 TO 1
    temp = A[i]
    A[i] = A[4-i]
    A[4-i] = temp
NEXT i
OUTPUT A[0], A[1], A[2]
Q11
What is the output?
A = [5, 2, 8, 1, 9]
max = A[0]
FOR i = 1 TO 4
    IF A[i] > max THEN
        max = A[i]
    END IF
NEXT i
OUTPUT max
Q12
What is the output?
A = [10, 20, 30, 40, 50]
FOR i = 0 TO 3
    A[i] = A[i] + A[i+1]
NEXT i
OUTPUT A[3]