ProgrammingModerateSSC CGL Tier 2 · IBPS PO Mains
The procedure below counts the digits of 2^10 by repeated division by 10. What is printed?
The procedure below counts the digits of 2^10 by repeated division by 10. What is printed?
N = 2^10; d = 0
while N > 0
N = N div 10; d = d + 1
end while
Print d- A. 3
- B. 4
- C. 5
- D. 11
Correct answer: B. 4
1024 has four digits, and the loop runs once for each digit until the value reaches 0. Subtracting one from the digit count gives 3, taking half of 10 gives 5, and counting the binary digits of 1024 gives 11.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- Euclid's algorithm finds gcd(48, 18) by replacing the pair (a, b) with (b, a mod b) until b is 0. The loop below counts how many times the…
- The number of ordered pairs (x, y) of positive integers with x y = 36 is counted by the procedure below. What is printed? count = 0 for x…
- The Josephus game: n = 7 people stand in a circle numbered 1 to 7, and every third person is removed (counting continues around the…
- The procedure below sums the prime factors of N = 360 counted with multiplicity (2 counted three times, and so on) by trial division. What…
- A product of ten consecutive numbers 1 x 2 x ... x 10 is computed. The procedure below counts how many of the numbers 1 to 10 are…
- Smallest n such that n! has at least 5 trailing zeros is searched for by the procedure below, where z(n) is the number of factors 5 in n!…