I've been given an assignment of writing both recurring and iterating programs of function, defined as:
T(n,0)=n, n>=0
T(0,m)=m, m>=0
T(n,m)=T(n-1,m)+2*T(n, m-1)
I am allowed to use only basic operations (so +, -, *, /, %) and not allowed to use most of "outside" functions from any libraries.
Writing recursion for that wasn't that much of a problem (code is in C):
int fTrec(int n, int m)
{
if(n==0)
return m;
else if(m==0)
return n;
else
return(fTrec(n-1, m)+2*fTrec(n, m-1));
}
However, making it into iteration turned out to be impossible for me. I've been trying to get it done for quite a while now, I've read quite a lot about it on internet - with very little success.
Every tip and all the help will be appreciated.
Thanks in advance!
Small edit: Forgot to add, I am limited to most basic tools and possibilites of C language. By this I mean using only one dimensional arrays, no pointers etc.