## Pages

Subscribe:
 Tweet

### Fibonacci Series In C

Fibonacci series is a mathematical sequence of numbers first created by Leonardo Fibonacci in 1202.Starting with 0 and 1 , each new number is sum of  the previous two.In mathematics terms Fn  is the Fibonacci sequence is defined by recurrence relation  Fn=Fn-1+Fn-2 .

Example :

Serial no       Fibonacci series

1                         0
2                         1
3                     0+1=1
4                     1+1=2
5                     1+2=3
6                     2+3=5
7                     3+5=8
9                     5+8=13
10                    8+13=21

Fibonacci Series Program  In C   :

```#include<stdio.h>
#include<conio.h>
#include<time.h>
long double fib(int);
main()
{
long double f;
long int t1,t2,t3,*t=NULL;
int n,i;
char ch;
do{
clrscr();
printf("\n\t Enter n(1-60):");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
t1=time(t);
f=fib(i);
t2=time(t);
t3=t2-t1;
printf("\tfib(%d)=%19.00Lf  time=%5ld  secs\n",i,f,t3);
}
printf("\n\t Continue (y/n):");
ch=getch();
}while(ch=='y'||ch=='Y');
}
long double fib (int n)
{
if (n<2)
return 1;
else
return fib(n-1)+fib(n-2);
}
```

Output : C program Fibonacci series calculate time of the each output number.