Here is an example of the Fibonacci Series program in C++ using recursion.

#include<iostream>    
using namespace std;      
void Fibonacci(int n)
{    
    static int num1=0, num2=1, num3;    
    if(n>0)
	{    
         num3 = num1 + num2;    
         num1 = num2;    
         num2 = num3;    
         cout<<num3<<" ";    
         Fibonacci(n-1);    
    }    
}    
int main()
{    
    int n;    
    cout<<"Please Enter the number to print the Fibonacci series : ";    
    cin>>n;    
    cout<<"Series are : ";    
    cout<<"0 "<<"1 ";  
    Fibonacci(n-2);   
     return 0;  
}

Output:

Please Enter the number to print the Fibonacci series : 5
0 1 1 2 3
Related Posts:

An Example For Connecting, Looping, Querying, and Displaying records in Pro*C/C++

Vinish Kapoor

An Oracle Apex Consultant, Oracle ACE, and founder of foxinfotech.in and orclqa.com a question and answer forum for developers.

Leave a Reply