## Featured Replies in this Discussion

- by arkoenig... I understand what your assignment is. What I am asking you to do is to explain the program that you wrote. You say that it is producing results that you do not expect. I am asking you what results you expect the program to produce, and why you expect the program to produce those results. An answer to that question would be something like: "Well, the first statement sets this variable to this value,…
- by arkoenig

What do lines 20-22 do? They don't seem to correspond to any part of the problem specification.

In particular, they seem to say that A(0,1) is equal to A(1,1). I see no justification for that claim.

I've just been trying numerous things to keep the program from running nonstop. I'm finna try something else and post the code

Revised Code and Output

```
#include <iostream>
using namespace std;
int A(int, int);
int main()
{
int m=NULL, n=0, count=0;
while(count<=7)
{
cout<<"A("<<m<<","<<n<<")"<<" ";
count++;
};
return 0;
}
int A(int m,int n)
{
if (m==0)
return n+1;
else if (n==0)
return A(m-1,1);
else
return A(m-1, A(m,n-1));
}
```

```
A(0,0) A(0,0) A(0,0) A(0,0) A(0,0) A(0,0) A(0,0) A(0,0) Press an
y key to continue . . .
```

What do you expect it to do and why?

This is for my Data Structures class. This is all we were given:

Ackermann's function is a recursive mathematical algorithm that can be used to test how well a computer performs recursion. Write a function A(m,n) that solves Ackermann's function. Use the following logic in your function:

If m=0 then return n+1

If n=0 then return A(m-1,1)

Otherwise, return A(m-1, A(m, n-1))

Test your function in a driver program that displays the following values:

A(0,0) A(0,1) A(1,1) A(1,2) A(1,3) A(2,2) A(3,2)

This is for my Data Structures class. This is all we were given:

I understand what your assignment is.

What I am asking you to do is to explain the program that *you* wrote.

You say that it is producing results that you do not expect.

I am asking you what results you expect the program to produce, and why you expect the program to produce those results. An answer to that question would be something like:

"Well, the first statement sets this variable to this value, and then the next statement prints that variable, so I would expect it to print the value of the variable" and so on.

I understand the program now...I have done it. Here's my results. Thanks!

```
#include <iostream>
using namespace std;
int A(int, int);
int main()
{
int m, n;
cout<<"Enter a value for m: ";
cin>>m;
cout<<"Enter a value for n: ";
cin>>n;
A(m,n);
return 0;
}
int A(int m,int n)
{
if (m==0)
{
cout<<"A("<<m<<","<<n<<") ";
return n+1;
}
else if (n==0)
{
cout<<"A("<<m<<","<<n<<") ";
return A(m-1,1);
}
else
{
cout<<"A("<<m<<","<<n<<") ";
return A(m-1, A(m,n-1));
}
}
```

Examples:

```
Enter a value for m:
0
Enter a value for n: 0
A(0,0) Press any key to continue . . .
```

```
Enter a value for m: 1
Enter a value for n: 2
A(1,2) A(1,1) A(1,0) A(0,1) A(0,2) A(0,3) Press any key to continue . . .
```

```
Enter a value for m: 1
Enter a value for n: 0
A(1,0) A(0,1) Press any key to continue . . .
```