ProgrammingModerateTCS NQT · Accenture pattern
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer c = 0
for (each d from 1 to 36)
if (36 mod d == 0)
c = c + 1
end if
end for
Print c- A. 6
- B. 9
- C. 8
- D. 7
Correct answer: B. 9
This counts the divisors of 36 = 2² × 3², which is (2 + 1)(2 + 1) = 9: 1, 2, 3, 4, 6, 9, 12, 18, 36. A perfect square has an odd number of divisors.
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 a = 15, b = 4 Print…
- What will be the output of the following pseudocode? Integer a = 5, b = 0 if (a > 3 && b != 0) Print "X" else if (a > 3 || b > 0) Print…
- What will be the output of the following pseudocode? Function fun(Integer n) if (n < 3) return n end if return fun(n - 1) + 2 fun(n - 3)…
- 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? Integer x = 0 for (each i from 1 to 5) for (each j from 1 to i) if ((i + j) mod 2 ==…