Testing.

Sunday, 22 January 2017

C programming language: C program to find Fibonacci sequence/series using recursion


#include<stdio.h>
#include<conio.h>
void FiboScrs(int);

int main()
{
    int n;
    printf("\nEnter Range of Fibonacci Series: ");
    scanf("%d",&n);

    printf("\nFibonacci Series: ");
    printf("%d %d ",0,1);
    FiboScrs(n);

    return 0;
}

void FiboScrs(int n)
{
    static long int fst=0,scnd=1,sum;

    if(n>0){
         sum = fst + scnd;
         fst = scnd;
         scnd = sum;
         printf("%ld ",sum);
         FiboScrs(n-1);
    }
getch();
}

No comments:

Post a Comment