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- A. 47
- B. 52
- C. 57
- 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.
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? (stop ends the program; arrays are indexed from 0) Integer a[6] = {3, 4, 5, 6, 1, 8}…
- What will be the output of the following pseudocode? (mod keeps the sign of the dividend (as in C); arrays are indexed from 0) Integer…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer calls = 0 Procedure…
- What will be the output of the following pseudocode? (Arrays are indexed from 0) Integer a[5] = {1, 2, 3, 4, 5}, comps = 0 Procedure…
- What will be the output of the following pseudocode? (mod keeps the sign of the dividend; code/char convert between letters and codes)…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer x = 1221, rev = 0…