Getting a term in the fibonacci sequence with recursion - Printable Version +- BP Forums (https://bpforums.info) +-- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=55) +--- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=56) +---- Forum: Java (https://bpforums.info/forumdisplay.php?fid=19) +---- Thread: Getting a term in the fibonacci sequence with recursion (/showthread.php?tid=593) |
Getting a term in the fibonacci sequence with recursion - brandonio21 - 08-06-2012 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] |