Fibonacci Series In C++ Using Recursion

Share on facebook
Share on twitter
Share on linkedin
Share on twitter
Share on tumblr

In this Basic C++ Program, we will have a look at the C++ Program to write Fibonacci Series using recursion.

Recursion In C++

When the function is called within the same function, it is known as recursion in C++. The function which calls the same function is known as a recursive function. A function that calls itself, and doesn’t perform any task after a function call, is known as tail recursion.

C++ Program Of Fibonacci Series using Recursion

#include<iostream>
using namespace std;
int fibonacci(int n)
{
    if((n==1)||(n==0))
    {
        return(n);
    }
    else
    {
        return(fibonacci(n-1)+fibonacci(n-2));
    }
}
int main()
{
    int n,i=0;
    cout<<"Input the number of terms for Fibonacci Series:";
    cin>>n;
    cout<<"\nFibonacci Series is as follows\n";
    while(i<n)
    {
        cout<<" "<<fibonacci(i);
        i++;
    }
    return 0;
}

You can also check: Fibonacci Series In C++ Using loop

Leave a Comment

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