ProgrammingHardProduct company OA

What is printed?

What is printed?
int z(int n) { return n < 5 ? 0 : n / 5 + z(n / 5); }
int main(void) { printf("%d %d", z(100), z(125)); }
  1. A. 20 31
  2. B. 24 30
  3. C. 20 25
  4. D. 24 31

Correct answer: D. 24 31

z(n) counts the trailing zeros of n!: multiples of 5, plus multiples of 25, plus 125, and so on. 100: 20 + 4 = 24. 125: 25 + 5 + 1 = 31. '20 25' counts only multiples of 5.

More C Programming questions

Exams that ask this topic