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- A. 4
- B. 6
- C. 5
- 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.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- What will be the output of the following pseudocode? Integer x = 1 for (k = 1 to 10) x = (x 3) mod 7 end for Print x
- What will be the output of the following pseudocode? (Arrays are indexed from 0.) Integer arr[5] = {3, 1, 4, 1, 5} for (i = 1 to 4) arr[i]…
- What will be the output of the following pseudocode? (calls counts every call, including the first; mod is the remainder.) Integer calls =…
- What will be the output of the following pseudocode? (& is bitwise AND.) Integer total = 0 for (i = 1 to 15) Integer n = i while (n != 0)…
- What will be the output of the following pseudocode? Integer c = 0, i for (i = 0; i < 10; i = i + 1) if (i mod 3 == 0) i = i + 2 end if c…
- What will be the output of the following pseudocode? (&& binds more tightly than ||; ! is NOT.) Integer a = 5, b = 10, c = 15 if (a > b ||…