WDTPD - Arrays
8 questions
Q1
What is the output?
A = [3, 0, 2, 1] OUTPUT: A[A[A[0]]]
Q2
What is the output?
A = [10, 20, 30, 40, 50]
FOR i = 0 TO 3
A[i] = A[i] + A[i+1]
NEXT
OUTPUT: A[3] Q3
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
OUTPUT: A[0], A[1], A[2] Q4
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
OUTPUT: max Q5
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
OUTPUT: A[4] 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
OUTPUT: s Q7
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
NEXT
OUTPUT: count Q8
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
OUTPUT: s