08-06-2012, 11:53 PM
Here is how to get the specified term in the Fibonacci sequence by using recursion. As you can see, it is a pretty elegant solution. However, it is rather slow.
[code2=java]public long GrabFibTermRecursive(int term)
{
if (term == 0) return 0;
if (term <= 2) return 1;
long fibTerm = (GrabFibTermRecursive(term - 1) + GrabFibTermRecursive(term - 2));
return fibTerm;
}[/code2]
[code2=java]public long GrabFibTermRecursive(int term)
{
if (term == 0) return 0;
if (term <= 2) return 1;
long fibTerm = (GrabFibTermRecursive(term - 1) + GrabFibTermRecursive(term - 2));
return fibTerm;
}[/code2]