/* * Computing Ackermann's function * * Matt Bishop, ECS 36A * * April 29, 2024 * -- original versionb */ #include <stdio.h> /* * macros for ease of changing */ #define M 3 #define N 4 /* * the function */ int ack(int m, int n) { /* base case: n = 0 */ if (m == 0) return(n + 1); /* recursice part */ if (n == 0) return(ack(m - 1, 1)); return(ack(m - 1, ack(m, n - 1))); } /* * the program */ int main(void) { /* do the computation of A(M, N) */ /* and print the result */ printf("ack(%d, %d) = %d\n", M, N, ack(M, N)); /* done! */ return(0); }
|
ECS 36A, Programming & Problem Solving Version of April 2, 2024 at 12:13PM
|
You can get the raw source code here. |