1
My teacher asked to make a program using double recursion to generate values of the Ackermann function, in which it is defined for integer and non-negative values m and n as this example:
I made that code but it’s making a mistake and I don’t know where I’m going wrong:
#include <stdlib.h>
#include <stdio.h>
int valor(int m, int n){
if (m == 0){
return n + 1;
} else if((m > 0) && (n == 0)){
return valor(m - 1, 1);
} else if((m > 0) && (n > 0)){
return valor(m - 1, valor(m, n - 1));
}
}
int teste(int n1, int n2){
int A;
A = valor(n1, n2);
return 0;
}
int main() {
for (int x = 0; x <= 4; ++x) {
for (int y = 0; y <= 4; ++y) {
teste(x,y);
}
}
return 0;
}
int value(int m, int n){ if (m == 0){ Return n + 1; } Else if((m > 0) && (n == 0)){ Return value(m - 1, 1); } Else if((m > 0) && (n > 0)){ Return value(m - 1, value(m, n - 1)); } } if m is <0 it returns what?
– Maurício Z.B