ProgrammingModerateAccenture · Cognizant GenC Next
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
String s = "CODE IS FUN", r = "", w = ""
for (each i from 0 to length(s) - 1)
if (s[i] == ' ')
r = r + w + " "
w = ""
else
w = s[i] + w
end if
end for
r = r + w
Print r- A. NUF SI EDOC
- B. FUN IS CODE
- C. EDOC SI FUN
- D. EDOC SI NUF
Correct answer: D. EDOC SI NUF
Each character is put in FRONT of the current word, so each word is reversed in place while the word order stays: EDOC SI NUF. The last word is added after the loop, so it is not lost.
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? (substring(t, i, k) is the k characters starting at index i; indices start at 0)…
- What will be the output of the following pseudocode? (& is AND, ^ is XOR, << is left shift) Integer a = 13, b = 11, carry, rounds = 0…
- What will be the output of the following pseudocode? ((b & 1) is evaluated before == ; & is AND, << and >> are shifts) Integer a = 13, b =…
- What will be the output of the following pseudocode? (^ is XOR, >> is right shift) Integer s = 0, g for (each i from 0 to 7) g = i ^ (i >>…
- What will be the output of the following pseudocode? Function possible(Integer out[5]) Stack st = empty Integer next = 1 for (each i from…
- What will be the output of the following pseudocode? Integer coins[4] = {9, 6, 5, 1} // sorted largest first Integer amt = 11, used = 0…