Fibonacci in C with Recursion

code from 1:

#include<stdio.h>
long getFibbTerm(int t)
{
    if(t==1||t==2)
        return 1;
    return getFibbTerm(t-1)+getFibbTerm(t-2);
}
int main()
{
    int t;
    for(t=1; t<10; t++)
    {
        printf("%d\t",getFibbTerm(t));
    }
    return 0;
}

Code from 0:

#include<stdio.h>
long getFibbTerm(int t)
{
    if(t==0)
        return 0;
    if(t==1)
        return 1;
    return getFibbTerm(t-1)+getFibbTerm(t-2);
}
int main()
{
    int t;
    for(t=0; t<10; t++)
    {
        printf("%d\t",getFibbTerm(t));
    }
    return 0;
}

 

Youtube source:

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published. Required fields are marked *