Ok, here is my code, which works fine, for implementing ackerman's function.
The question I have is, since the function's value increases so quickly, the numbers become so large so fast that the program just crashes if anything after A(3,4) is entered. I assume this is because the variables are only able to hold into the two billion range and the output would be much much higher, so the program crashes when the output would be out of the variable's range. Is there anyway around this? I want to be able to get an output for A(5,5). Thanks!
The question I have is, since the function's value increases so quickly, the numbers become so large so fast that the program just crashes if anything after A(3,4) is entered. I assume this is because the variables are only able to hold into the two billion range and the output would be much much higher, so the program crashes when the output would be out of the variable's range. Is there anyway around this? I want to be able to get an output for A(5,5). Thanks!
Code:
#include "stdafx.h" #include <iostream> using namespace std; int A (int m, int n) { if (m == 0) return n + 1; if (n == 0) return A(m - 1, 1); return A(m - 1, A(m, n - 1)); } int _tmain(int argc, _TCHAR* argv[]) { int m, n; cout << "Enter m:" << endl; cin >> m; cout << "Enter n:" << endl; cin >> n; cout << "A(" << m << "," << n << ") = " << A(m, n) << endl; return 0; }
Comment