ProgrammingVery hardProduct company OA

What is printed?

What is printed?
int m(int n) { return n > 100 ? n - 10 : m(m(n + 11)); }
int main(void) { printf("%d %d", m(50), m(105)); }
  1. A. 50 95
  2. B. 61 95
  3. C. 91 95
  4. D. 91 105

Correct answer: C. 91 95

This is McCarthy's 91 function: for any n ≤ 100 the nested calls climb above 100 and settle back to exactly 91; for n > 100 it simply returns n − 10. So m(50) = 91 and m(105) = 95.

More C Programming questions

Exams that ask this topic