Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting a term in the fibonacci sequence with recursion
#1
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]
My Blog | My Setup | My Videos | Have a wonderful day.


Possibly Related Threads…
Thread Author Replies Views Last Post
  Getting a term in the fibonacci sequence without recursion brandonio21 0 5,701 08-06-2012, 11:51 PM
Last Post: brandonio21

Forum Jump:


Users browsing this thread: 1 Guest(s)