ProgrammingHardCapgemini · Infosys pattern

What will be the output of the following pseudocode (counting words longer than the average word length)?

What will be the output of the following pseudocode (counting words longer than the average word length)?
List words = {"the", "quick", "brown", "fox", "jumps"}
Real avg = averageLength(words)
Integer c = 0
for (each w in words)
    if (length(w) > avg)
        c = c + 1
    end if
end for
Print c
  1. A. 2
  2. B. 4
  3. C. 3
  4. D. 5

Correct answer: C. 3

Word lengths are 3,5,5,3,5, averaging 21/5=4.2. Words longer than 4.2 are 'quick'(5), 'brown'(5), 'jumps'(5) -- three words.

More Pseudocode and Code Tracing questions

Exams that ask this topic