C++ Program for Fibonacci Series Using Recursion using function

Fibonacci Series the next number is the sum of the previous two numbers for example 0, 1, 1, 2, 3, 5, 8, 13, 21, etc. The first two numbers of the Fibonacci series are 0 and 1.

C++ Program for Fibonacci Series Using Recursion using function

#include <iostream>  
using namespace std;  
int main() {  
  int n1=0,n2=1,n3,i,number;    
 cout<<"Enter the number of elements: ";    
 cin>>number;    
 cout<<n1<<" "<<n2<<" ";    
 for(i=2;i<number;++i)   
 {    
  n3=n1+n2;    
  cout<<n3<<" ";    
  n1=n2;    
  n2=n3;    
 }    
   return 0;  
   }  

Output of Program

Enter the number of elements: 10
0 1 1 2 3 5 8 13 21 34