Read post
#include <stdio.h>
int fib(int n)
{
int array[2]={0,1},temp=0,i;
if (n == 0)
return 0;
else if (n == 1)
return 1;
else
{
for (i=n; i > 2;i--)
{
temp=array[0]+array[1];
array[0]=array[1];
array[1]=temp;
}
return (array[0]+array[1]);
}
}
int main(void)
{
int a[40],i=0,j;
while ( scanf("%d",&a[i]) != EOF) i++;
j=0;
while (j < i )
{
printf("The Fibonacci number for %d is %d\n",a[j],fib(a[j]));
j++;
}
return 0;
}
Reply
|