Fibonacci Series

Submitted by Karthikeyan on Tue, 08/09/2009 - 17:26

Sample C Program to find Fibonacci series


#include
main()
{
    int number;
    clrscr();
    printf("\n\n\t\t Fibonacci Series");
    printf("\n\n\t\t ****************");
    printf("\n\n\t\t Enter a number: ");
    scanf("%d", &number);
	printf("\t\t\t %d\n\n", number);
    fib(number);
    printf("\n\t\t ******************");
    getch();
}
fib(int m)
{
    static int f1=0, f2=1;
    int f;
    if(m<2)
    {
        f1 =0;
        f2 = 1;
    }
    else
    {
        fib(m-1);
        f=f2;
        f2=f1+f2;
        f1=f;
    }
    printf("\t\t\t\t%d\n", f1);
}