1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include <stdio.h>
int ack(int m, int n)
{
if (m == 0) return n+1;
if (n == 0) return ack( m - 1, 1 );
return ack( m - 1, ack( m, n - 1 ) );
}
int main()
{
for (int i = 0; i < 6; ++i)
for (int j = 0; j < 6; ++j)
printf("ack(%d,%d) = %d\n", i, j, ack(i,j));
return 0;
}
|
ack(0,0) = 1
ack(0,1) = 2
ack(0,2) = 3
ack(0,3) = 4
ack(0,4) = 5
ack(0,5) = 6
ack(1,0) = 2
ack(1,1) = 3
ack(1,2) = 4
ack(1,3) = 5
ack(1,4) = 6
ack(1,5) = 7
ack(2,0) = 3
ack(2,1) = 5
ack(2,2) = 7
ack(2,3) = 9
ack(2,4) = 11
ack(2,5) = 13
ack(3,0) = 5
ack(3,1) = 13
ack(3,2) = 29
ack(3,3) = 61
ack(3,4) = 125
ack(3,5) = 253
ack(4,0) = 13
ack(4,1) = 65533
Segmentation fault (core dumped) |