1. 示例代码:
// 用递归调用求 Ackerman(m, n) 的值
#include <stdio.h>
static int Ackerman(int m, int n);
int main(void)
{
int m = 0, n = 0;
printf("Please input m and n: ");
scanf_s("%d%d", &m, &n);
printf("Ackerman(%d, %d) = %d\n", m, n, Ackerman(m, n));
return 0;
}
static int Ackerman(int m, int n)
{
int ret = 0;
if (m == 0) {
ret = n + 1;
} else if (n == 0) {
ret = Ackerman(m - 1, 1);
} else {
ret = Ackerman(m - 1, Ackerman(m, n - 1));
}
return ret;
}
2. 输出示例: