1. 示例代码:
/* 用递归调用求 Ackerman(m, n) 的值 */
#include <stdio.h>
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;
}
int Ackerman(int m, int n)
{
int z = 0;
if (m == 0) {
z = n + 1;
} else if (n == 0) {
z = Ackerman(m - 1, 1);
} else {
z = Ackerman(m - 1, Ackerman(m, n - 1));
}
return z;
}
2. 输出示例: