Skip to content

Instantly share code, notes, and snippets.

@victorfdes
Last active October 7, 2017 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorfdes/cdf1915dc5564ae801b4edc8acb2b283 to your computer and use it in GitHub Desktop.
Save victorfdes/cdf1915dc5564ae801b4edc8acb2b283 to your computer and use it in GitHub Desktop.
Ackermann's function (recursive)
#include <bits/stdc++.h>
using namespace std;
int ack(int m, int n){
int ans;
if( m == 0 ) ans = n + 1;
else if( n == 0 ) ans = ack(m - 1, 1);
else ans = ack(m - 1, ack(m, n-1));
return (ans);
}
int main(){
printf( "ack(%d, %d) is %d\n", 4, 0, ack(4,0) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment