ProgrammingVery hardGATE CS · Competitive coding (CP)
What is printed?
What is printed?
#include <stdio.h>
int A(int m, int n) {
if (m == 0) return n + 1;
if (n == 0) return A(m - 1, 1);
return A(m - 1, A(m, n - 1));
}
int main(void) {
printf("%d", A(2, 2));
}- A. 7
- B. 4
- C. 29
- D. 6
Correct answer: A. 7
A(1,n) = n + 2 and A(2,n) = 2n + 3, so A(2,2) = 7, and the recursion always terminates. 4 is A(1,2), stopping one level early, 29 is A(3,2) = 2^5 - 3, and 6 misremembers A(2,n) as 2n + 2.
More C Programming questions
- What is printed? c #include <stdio.h> unsigned long long g(unsigned n, unsigned long long acc) { return n == 0 ? acc : g(n - 1, acc 3 +…
- What is printed? c #include <stdio.h> long long memo[50]; int calls = 0; long long f(int n) { calls++; if (n < 2) return 1; if (memo[n])…
- What is printed? c #include <stdio.h> #include <stdlib.h> int cmp(const void a, const void b) { int x = (const int )a, y = (const int )b…
- What is printed? c #include <stdint.h> #include <stdio.h> int main(void) { uint16t x = 0xABCD; x = (uint16t)((x << 4) | (x >> 12))…
- Assume unsigned int is 32 bits. What is printed? c #include <stdio.h> int main(void) { unsigned n = 0x1FFFF, p = 1; while (p 2 <= n) p =…
- Assume uint32t is 32 bits. What is printed? c #include <stdint.h> #include <stdio.h> int main(void) { uint32t v = 0x12345678u; uint32t r =…