Printing Fibonacci Series in C Program Source Code



#include <stdio.h>
//fibonacci series
//0 1 1 2 3 5........
//using recursive function
void fibo(int,int);

int main()
{
    int old=0,current=1;
    printf("%d\t%d\t",old,current);
    fibo(old,current); //function calling

    return 0;
}
void fibo(int old, int current)
{
    static int terms = 2;//value won't change until the end of the program
    int new; 
    
    if(terms<20)
    {
        new=old+current;
        printf("%d\t", new);
        terms = terms+1;
        fibo(current,new);
    }
    else
    {
        return;
    }
}

Comments