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)); }- A. 9
- B. 20
- C. 6
- 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
- Assume 8-bit unsigned char. What is printed? c int n = 0; for (unsigned char c = 0; c < 300; c++) { n++; if (n > 1000) break; }…
- Assume IEEE-754 float (24-bit significand) and 32-bit int. What is printed? c int big = 16777217; / 2^24 + 1 / float f = big; printf("%d"…
- Assume 8-bit unsigned char. What is printed? c int i; unsigned char c; double d; d = c = i = 300 + 0.7; printf("%d %d %.1f", i, c, d);
- Why is memcmp(&a, &b, sizeof a) == 0 an unreliable way to test whether two struct variables a and b have equal members?
- What is printed? c int c = 0; int f(int n) { c++; return n > 0 && (f(n - 1) || f(n - 2)); } int main(void) { int r = f(4); printf("%d %d"…
- What is printed? c char buf[32], p = buf; for (int i = 1; i <= 4; i++) p += sprintf(p, "%d,", i i); p[-1] = '0'; printf("%s %td", buf, p…