ProgrammingHardTCS NQT Advanced · Infosys SP
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 n = 360, d = 2, s = 0, c = 0
while (n > 1)
while (n mod d == 0)
s = s + d
c = c + 1
n = n / d
end while
d = d + 1
end while
Print s, c- A. 17 6
- B. 10 3
- C. 17 3
- D. 15 6
Correct answer: A. 17 6
The loops strip out prime factors with repetition: 360 = 2 × 2 × 2 × 3 × 3 × 5. Their sum is 17 and there are 6 of them: 17 6. 10 3 adds only the distinct primes.
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 count = 0, s for (each n from 2 to 500) s = 1 for (each d from 2 to n - 1) if…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer count = 0, n, s, d for…
- 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…