Skip to content

Commit

Permalink
Create fibonacci series using recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
shresthmamchand authored Oct 24, 2021
1 parent 8119d2a commit 767ba5d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions fibonacci series using recursion
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include<iostream>
using namespace std;
void printFibonacci(int n){
static int n1=0, n2=1, n3;
if(n>0){
n3 = n1 + n2;
n1 = n2;
n2 = n3;
cout<<n3<<" ";
printFibonacci(n-1);
}
}
int main(){
int n;
cout<<"Enter the number of elements: ";
cin>>n;
cout<<"Fibonacci Series: ";
cout<<"0 "<<"1 ";
printFibonacci(n-2); //n-2 because 2 numbers are already printed
return 0;
}

0 comments on commit 767ba5d

Please sign in to comment.