Fibonacci series with recursion function - C++

Q. Write a C++ program to print the Fibonacci series using recursion function.

Answer:

Following program is displaying the Fibonacci series using recursion function. Recursive function is a function which calls itself. It allows to call a function inside the same function. Fibonacci series is the sum of two preceding ones. For example : 1 1 2 3 5 8 13 . . .

#include<iostream>
using namespace std;
int fibonacci(int num)
{
        if((num==1)||(num==0))
        {
                return(num);
        }
        else
        {
                return(fibonacci(num-1)+fibonacci(num-2));
        }
}
int main()
{
        int num,i=0;
        cout<<"\n How many numbers you want for Fibonacci Series : ";
        cin>>num;
        cout<<"\n Fibonacci Series : ";

        while(i<num)
        {
                cout<<" "<<fibonacci(i);
                i++;
        }
    return 0;
}


Output:

fibonacci series