Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting a term in the fibonacci sequence without recursion
#1
Here is a quick code snippet that gets the specified term of the Fibonacci sequence without recursion.
[code2=java]public long GrabFibTerm(int term)
{
if (term == 1) return 0;
if (term == 2) return 1;

long a = 0;
long b = 1;

int count = 2;
while (count <= term)
{
long oldB = b;
b = (a + b);
a = oldB;

count++;
}
return b;
}[/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 with recursion brandonio21 0 5,878 08-06-2012, 11:53 PM
Last Post: brandonio21

Forum Jump:


Users browsing this thread: 1 Guest(s)