ProgrammingModerateTCS NQT · Accenture pattern

What will be the output of the following pseudocode? (Strings are indexed from 0.)

What will be the output of the following pseudocode? (Strings are indexed from 0.)
String s = "PSEUDOCODE"
Integer v = 0
for (i = 0 to length(s) - 1)
    if (s[i] == 'A' or s[i] == 'E' or s[i] == 'I' or s[i] == 'O' or s[i] == 'U')
        v = v + 1
    end if
end for
Print v
  1. A. 4
  2. B. 6
  3. C. 5
  4. D. 3

Correct answer: C. 5

P S E U D O C O D E: the vowels are E, U, O, O, E → 5. Counting distinct vowels (E, U, O) gives 3; missing the final E (off-by-one on the loop bound) gives 4.

More Pseudocode and Code Tracing questions

Exams that ask this topic