In: Computer Science
Code:
#include<stdio.h>
int fibno(int n)
{
int f1=0,f2=1,i;/*Declared variables*/
if(n==0)
{
return 0;/*When n is 0 we return
0*/
}
else if(n==1)
{
return 1;/*When n is 1 we return
1*/
}
else
{
int sum;
for(i=1;i<n;i++)
{/*Here we calculate the fibnocci
series*/
sum=f1+f2;
f1=f2;
f2=sum;
}
return sum;
/*Finally we return the
number*/
}
}
int main()
{
int i=1,n=15;/*Here we declared the variables*/
printf("First 15 Fibonacci series: \n");
for(i=0;i<n;i++)
{
printf("%d\t%d\n",i+1,fibno(i));
/*Here we call the function for
every number*/
}
}
Output:
indentation: