**// recursive version**

int fib( n )

{

if ( n < 2 )

return 1;

else

return fib ( n-1 ) + fib ( n-2 );

}

**//iterative version**

int fib( n )

{

int f1 =1, f2 = 1;

if ( n < 2 )

return 1;

for ( i = 1; i < N; i++)

{

f = f1 + f2;

f1= f2;

f = f1;

}

return f;

}

### Like this:

Like Loading...

*Related*

This entry was posted on August 28, 2007 at 5:00 pm and is filed under Programing Question in C. You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.

## Leave a Reply