ProgrammingModerateTCS NQT · Accenture pattern
What will be the output of the following pseudocode? (All variables are integers, so / is integer division.)
What will be the output of the following pseudocode? (All variables are integers, so / is integer division.)
Integer s = 0
for (each i from 1 to 10)
s = s + (i * i) / 3
end for
Print s- A. 385
- B. 126
- C. 127
- D. 128
Correct answer: B. 126
Each term is cut down separately: 0, 1, 3, 5, 8, 12, 16, 21, 27, 33, which adds up to 126. Dividing the total at the end (385 / 3 = 128) gives the trap.
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? (All variables are integers, so / is integer division.) Integer n = 100, c = 0, d = 5…
- What will be the output? (calls counts every call, including the first.) Integer calls = 0 Function fun(Integer a, Integer b) calls =…
- What will be the output of the following pseudocode? Integer c = 0 for (i = 1; i < 64; i = i 2) for (j = i; j < 64; j = j + i) c = c + 1…
- What will be the output of the following pseudocode? (& is bitwise AND, | is bitwise OR, ^ is bitwise XOR, << and >> are left and right…
- What will be the output of the following pseudocode? (& is bitwise AND, | is bitwise OR, ^ is bitwise XOR, << and >> are left and right…
- What will be the output of the following pseudocode? (Arrays are indexed from 0.) Integer arr[4] = {2, 3, 1, 0} for (each i from 0 to 3)…