mercredi 18 mars 2020

Recursive function With c++ (coordinates)

Hello guys i've found this exercice and i tried to solve it can you check my answer please [1]`[1]: https://i.stack.imgur.com/EBtEF.jpg And this is my code

#include <iostream>
using namespace std;
int A (int m, int n)
{
if (m==0)
{return n+1;

else if (m>0 && n==0)
return A(m-1,1);

else if (m>0 && n>0)
return A(m-1,A(m,n-1));
}
int main () {
    int m,n;
    cout<<"entrer m et n : ";
    cin>>m>>n;
    cout<<"A = " << A(m,n);
    return 0;
    }

Aucun commentaire:

Enregistrer un commentaire