ProgrammingVery hardCAT · MBA placement
For N = 100 the procedure below counts how many times 5 divides the factorials, that is, the number of trailing zeros of 100!. The count is the sum of floor(N / 5^k) for k = 1, 2, 3, ... What is printed?
For N = 100 the procedure below counts how many times 5 divides the factorials, that is, the number of trailing zeros of 100!. The count is the sum of floor(N / 5^k) for k = 1, 2, 3, ... What is printed?
count = 0; p = 5
while p <= N
count = count + N div p
p = p * 5
end while
Print count- A. 97
- B. 66
- C. 24
- D. 20
Correct answer: C. 24
The factor 5 appears 20 + 4 = 24 times in the product 1 x 2 x ... x 100, and that is the trailing zero count. Counting factors of 2 gives 97, adding 5 instead of multiplying by 5 counts 5s in a different way, and stopping after the first power gives 20.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- The procedure below reverses the digits of N = 120450 (trailing zeros disappear in the numeric result). What is printed? rev = 0; m = N…
- An Armstrong number of three digits equals the sum of the cubes of its digits. The procedure below counts how many three-digit numbers…
- Compute C(10, 3) modulo 7 using Pascal's rule C(n, k) = C(n-1, k-1) + C(n-1, k), reducing every entry mod 7. What is printed? build the…
- By Fermat's little theorem, for a prime p and a not divisible by p, the inverse of a is a^(p-2) mod p. The procedure below finds the…
- A pair (a, b) with 1 <= a < b <= 20 is called coprime if gcd(a, b) = 1. The procedure below counts coprime pairs. What is printed? count =…
- The sum of the divisors of N = 28 is computed by the procedure below. A number is perfect when its proper divisors (excluding N) add up to…