[RESOLVED] Remove recursion
Hi all
I need help converting this recursive function to non-recursive
Code:
int nnn(int n){
if(n>1){
return nnn(n-1)+nnn(n-2);
}else{
return 1;
}
}
VB Code:
Function nnn(N as Integer) As Integer
If N>1 Then
Return nnn(N-1)+nnn(N-2);
Else
Return 1;
End If
End Function
Re: [RESOLVED] Remove recursion
I think the environment I was testing in was causing the inaccuracies I experienced, this seems fine in excel (paste into b1 and add N into a1):
=POWER((SQRT(5)+1)/2,A1)/SQRT(5)-POWER((-SQRT(5)+1)/2,A1)/SQRT(5)