Last active
October 7, 2017 20:49
-
-
Save victorfdes/cdf1915dc5564ae801b4edc8acb2b283 to your computer and use it in GitHub Desktop.
Ackermann's function (recursive)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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