ProgrammingHardGoldman Sachs OA · TCS Digital
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 = 50, c = 0, p = 2
while (p <= n)
c = c + n / p
p = p * 2
end while
Print c- A. 47
- B. 25
- C. 31
- D. 12
Correct answer: A. 47
Legendre's formula counts the factors of 2 in 50!: 25 + 12 + 6 + 3 + 1 = 47 (so 50! ends in 47 zero bits).
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 n = 36, s = 0 for…
- What will be the output of the following pseudocode? (& is bitwise AND) Integer mask = 13, s, c = 0 s = mask while (s > 0) c = c + 1 s =…
- What will be the output of the following pseudocode? (integers are 32-bit; & is AND, << and >> are shifts) Integer x = 45 Integer y = (x…
- What will be the output of the following pseudocode? // BST: smaller keys go left, larger (or equal) keys go right Insert into an empty…
- What will be the output of the following pseudocode? Insert into an empty BST, in this order: 8, 3, 10, 1, 6, 14, 4, 7, 13 Queue q =…
- What will be the output of the following pseudocode? (Print writes its values on one line, separated by spaces) Integer burst[3] = {5, 3…