Pages

Subscribe:

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.


No Preview



If you have any Further Information and Quires about this Article don't hesitate to comment in comment box below.
                                                           AND

 If you like this article , like our Facebook like page and click  +1 to support 123techguide
comments powered by Disqus
 

Listed In

Bloggers - Meet Millions of Bloggers http://Link-exchange.comxa.com
Blog Search: The Source for Blogs Internet Blogs

Disclaimer

The contents in this blog are taken from various sources available over the internet, therefore we do not gurantee of it's accuracy, if you find any of the content in the blog is infringing it's copyright, please do email us on '123techguide@gmail.com' and we will make sure to remove the same from the blog at the earliest.