ProgrammingModerateAccenture · Cognizant pattern
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer s = 0, i = 1
while (i <= 20)
s = s + i
i = i * 2 + 1
end while
Print s- A. 11
- B. 26
- C. 57
- D. 15
Correct answer: B. 26
i goes 1, 3, 7, 15 (each is 2i + 1), and the next value 31 fails the test. s = 1 + 3 + 7 + 15 = 26.
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.) Function g(Integer n) if (n…
- What will be the output of the following pseudocode? (Arrays are indexed from 0.) Integer arr[6] = {5, -2, 3, -1, 4, -6} Integer s = 0, m…
- What will be the output of the following pseudocode? Integer x = 7, y = 3 Print x mod y y + x / y
- What will be the output of the following pseudocode? (Arrays are indexed from 0.) Integer arr[6] = {1, 2, 3, 4, 5, 6} for (each i from 0…
- How many times is fun called in total when fun(6) is evaluated? Function fun(Integer n) if (n <= 2) return 1 end if return fun(n - 1) +…
- What will be the output of the following pseudocode? Integer c = 0, j for (each i from 1 to 10) j = i while (j <= 10) c = c + 1 j = j + i…