ProgrammingHardTCS NQT · Accenture
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 count = 0, n, s, d
for (each x from 100 to 999)
n = x
s = 0
while (n > 0)
d = n mod 10
s = s + d * d * d
n = n / 10
end while
if (s == x)
count = count + 1
end if
end for
Print count- A. 3
- B. 5
- C. 4
- D. 1
Correct answer: C. 4
The loop counts 3-digit numbers equal to the sum of the cubes of their digits (Armstrong numbers): 153, 370, 371 and 407. Output 4.
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 c = 0 for (each y from 1890 to 2010) if ((y mod 4 == 0 AND y mod 100 != 0) OR…
- What will be the output of the following pseudocode? (AND has higher precedence than OR) Integer a = 5, b = 2, c = 3 if (a > b OR b > c…
- What will be the output of the following pseudocode? Integer calls = 0 Function f(Integer m, Integer n) calls = calls + 1 if (m == 0 OR n…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer a = 1, b = 100, steps…
- What will be the output of the following pseudocode? Integer a[5] = {7, 7, 5, 7, 6} Integer m1 = -1, m2 = -1 for (each i from 0 to 4) if…
- What will be the output of the following pseudocode? Integer a[5] = {2, 3, 4, 5, 1}, passes = 0, n = 5 Boolean swapped for (each i from 0…