ProgrammingModerateTCS NQT · Wipro

What will be the output of the following pseudocode? (code(c) gives a letter's character code; 'A' to 'Z' have consecutive codes)

What will be the output of the following pseudocode? (code(c) gives a letter's character code; 'A' to 'Z' have consecutive codes)
String w = "ZEBRA"
Integer s = 0
for (each i from 0 to length(w) - 1)
    s = s + (code(w[i]) - code('A') + 1)
end for
Print s
  1. A. 47
  2. B. 52
  3. C. 57
  4. D. 50

Correct answer: B. 52

Each letter contributes its position in the alphabet: Z = 26, E = 5, B = 2, R = 18, A = 1. Total 52.

More Pseudocode and Code Tracing questions

Exams that ask this topic