Pages

To generate a Fibonacci series in C Programming

Monday 8 July 2013
The first two Fibonacci numbers are 0 and 1 then next number is addition of previous two numbers.

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89.....
In mathematics it is defined by recurrence relation.


#include<stdio.h>
#include<conio.h>

void main()
{
    int a,b,c,i,n;
    clrscr();
    a=0;
    b=1;

    printf("\n enter n for how many times generate series");
    scanf("%d",&n);
    printf("\n FIBONACCI SERIES\n");
    printf("\t%d\t%d",a,b);

    for(i=0;i<n;i++)
    {
             c=a+b;
             a=b;
             b=c;
             printf("\t%d",c);
     }
     getch();
}

No comments:

Post a Comment