trying to create Fibonacci Sequence
I don't know what I'm doing wrong. I'm trying to print "fn" of the
sequence. I based it on someone else's code. Any thoughts?
Here is my code:
int num = n;
int fn = 1;
int f1 = 0;
int f2 = 1;
for (int i = 2; i < n; i++)
{
fn = f1 + f2;
f1 = f2;
f2 = fn;
}
System.out.print( "fib( " + num + " ) is ");
System.out.println( fn );
No comments:
Post a Comment