ProgrammingHardProduct company OA · GATE CS

What is printed?

What is printed?
int paths(int r, int c) {
    return (r == 0 || c == 0) ? 1 : paths(r - 1, c) + paths(r, c - 1);
}
int main(void) { printf("%d", paths(3, 3)); }
  1. A. 9
  2. B. 20
  3. C. 6
  4. D. 27

Correct answer: B. 20

paths counts monotone lattice paths that make r moves one way and c moves the other: choose which 3 of the 6 moves go one way, C(6, 3) = 20. '9' is the number of cells in a 3 × 3 grid, and 6 is the length of each path.

More C Programming questions

Exams that ask this topic