1 Write a classic recursive function of N that returns the N

1. Write a classic recursive function of N that returns the Nth Fibonacci number.

2. Write an accumulator recursive function of N that returns the Nth Fibonacci number.

3. Write a recursive function of N that returns the Nth Fibonacci number, calculating each number once only. (Hint: use a dictionary!)

4. Implement an accumulator recursive function of N that returns a list of all the Fibonacci numbers, calculating each number once only. (Hint: no dictionary needed!)

Solution

C program to find nth Fibonacci term using recursion

#include <stdio.h>

//Function declaration part(Recursive function to find nth Fibonacci term

)

long long fiboseries(int num);

int main()

{

    int num;

    long long fibonum;

     

    printf(\"Enter any number to find nth fibonacci term: \");

    scanf(\"%d\", &num);

     

    fibonum = fiboseries(num);

     

    printf(\"fibonacci series of the num is \", num, fibonum);

     

    return 0;

}

long long fiboseries (int num)

{

    if(num == 0) //initial condition

        return num;

    else if(num == 1) //initial condition

        return num;

    else

        return fiboseries(num-1) + fiboseries(num-2);

}

1. Write a classic recursive function of N that returns the Nth Fibonacci number. 2. Write an accumulator recursive function of N that returns the Nth Fibonacci

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site