ProgrammingModerateAccenture · Cognizant pattern
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer n = 10, s = 0
for (i = 1 to n)
if (n mod i == 0)
s = s + i
end if
end for
Print s- A. 8
- B. 17
- C. 55
- D. 18
Correct answer: D. 18
Divisors of 10 are 1, 2, 5, 10 → 18. Excluding n itself (proper divisors) gives 8; a perfect number would have proper-divisor sum equal to n.
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? Integer Function f(Integer x, Integer y) if (x > y) return f(x - y, y) if (x < y)…
- What will be the output of the following pseudocode? Integer s = 0, i = 0 while (true) i = i + 1 if (i mod 4 == 0) continue s = s + i if…
- What will be the output of the following pseudocode? Integer m[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}} Integer d1 = 0, d2 = 0, t = 0 for…
- What will be the output of the following pseudocode? Integer c = 0 Procedure rec(Integer k) c = c + 1 if (k <= 1) return rec(k / 2) rec(k…
- What will be the output of the following pseudocode? // 32-bit signed integers with two's-complement wrap-around Integer x = 2147483647…
- What will be the output of the following pseudocode? Integer a = 13, b = 10 // 1101 and 1010 Print a & b, a | b, a ^ b, ~a // 32-bit two's…