ProgrammingHardInfosys SP · Goldman Sachs OA
What will be the output of the following pseudocode? (^ is bitwise XOR)
What will be the output of the following pseudocode? (^ is bitwise XOR)
Integer s = 0
for (each i from 0 to 15)
s = s + (i ^ 5)
end for
Print s- A. 120
- B. 80
- C. 125
- D. 40
Correct answer: A. 120
For 0 ≤ i ≤ 15, i ^ 5 is again a number from 0 to 15, and different i give different results, so the values are just 0 to 15 in another order. The sum is 0 + 1 + … + 15 = 120.
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? (parameters are passed by value; inside g, x is the global x; operands are evaluated…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division; + joins strings) Function…
- What is the time complexity of the following pseudocode, as a function of n? i = n while (i > 1) j = i while (j < n) j = j 2 end while i =…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer c = 0, i = 1, j while…
- What will be the output of the following pseudocode? (stop ends the program; code(c) gives a letter's character code) String s =…
- What will be the output of the following pseudocode? (Arrays are indexed from 0) Integer a[8] = {1, 1, 2, 2, 2, 3, 5, 5} Integer k = 1 for…