Question PSC-ARR-0046
MediumWhat will be printed by the following pseudocode?
Integer a[5] = {5, 1, 4, 2, 8}
Integer i, j, t, swaps = 0
for (each i from 0 to 3)
for (each j from 0 to 3 - i)
if (a[j] > a[j + 1])
t = a[j]; a[j] = a[j + 1]; a[j + 1] = t
swaps = swaps + 1
end if
end for
end for
Print swaps
- A.
5
- B.
10
- C.
Sign up free to see the answer and a step-by-step explanation.