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)
Function gcd(Integer a, Integer b)
while (b != 0)
Integer t = a mod b
a = b
b = t
end while
return a
End Function
Integer L = 1
for (each i from 1 to 10)
L = L / gcd(L, i) * i
end for
Print L- A. 3628800
- B. 2520
- C. 5040
- D. 1260
Correct answer: B. 2520
L / gcd(L, i) × i is lcm(L, i), so L becomes lcm(1, …, 10) = 2³ × 3² × 5 × 7 = 2520. 3628800 = 10! multiplies without dividing.
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? Function sd(Integer n) Integer s = 0 for (each d from 1 to n - 1) if (n mod d == 0) s…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division; + joins strings) String digits…
- What will be the output of the following pseudocode? (code(c) gives a letter's character code and char(k) the reverse) String s =…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division; arrays are indexed from 0)…
- What will be the output of the following pseudocode? Integer c = 0 for (each i from 1 to 10) for (each j from 1 to i) if (j j > i) break…
- What will be the output of the following pseudocode? Integer m[3][3] = {{5, 1, 7}, {2, 9, 3}, {8, 4, 6}} Integer c = 0 Boolean peak for…