#include <stdio.h>
int fib(int);
int main(int argc,int *argv[])
{
int i;
for(i=1;i<21;i++)
{
printf("%d ",fib(i));
}
system("pause");
return 0;
}
int fib(int number)
{
if ( number <= 0 )
{
return 0;
}
if (number == 1 || number == 2)
{
return 1;
}
int f1=1,f2=1,fn;
int i;
for (i=3;i<=number;++i)
{
fn = f1 +f2;
f1 = f2;
f2 = fn;
}
return fn;
}
|