Monday, July 31, 2017

Find fibonacci series in C

#include<stdio.h>
void fibonacci(int);
void main()
{
    int n,first=0,second=1;
    printf("Enter the number of fibonacci series to be printed : ");
    scanf("%d",&n);
    printf("%d\t%d\t",first,second);
    fibonacci(n);
    getch();
}
void fibonacci(int n)
{
    static int first=0,second=1,sum=0;
    if(n-2>0)
    {
        sum=first+second;
        first=second;
        second=sum;
        printf("%d\t",sum);
        fibonacci(n-1);
    }
}

0 comments:

Post a Comment