ProgrammingModerateLTIMindtree · Cognizant GenC

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer a[5] = {3, 8, 2, 7, 5}, i, total = 0, s = 0
for (i = 0; i < 5; i = i + 1)
    total = total + a[i]
end for
for (i = 0; i < 5; i = i + 1)
    if (a[i] * 5 > total)
        s = s + a[i]
    end if
end for
Print s
  1. A. 20
  2. B. 15
  3. C. 23
  4. D. 8

Correct answer: B. 15

total = 25, so a[i] * 5 > 25 means a[i] > 5; the elements 8 and 7 give 15.

More Pseudocode and Code Tracing questions

Exams that ask this topic