Skip to content

Commit

Permalink
Update fibonacci.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
TanujRohilla authored Oct 1, 2018
1 parent e298c11 commit b9db699
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions fibonacci/fibonacci.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#include <iostream>

template <int N> int Fib(){ return Fib<N-1>() + Fib<N-2>(); }
template <> int Fib<1>() { return 1; }
template <> int Fib<0>() { return 1; }

//Fibonacci Series using Recursion
#include<iostream>
using namespace std;
int main()
int fib(int n)
{
if (n <= 1)
return n;
return fib(n-1) + fib(n-2);
}

int main ()
{
int num = 0;
cout << "Enter the number of terms: ";
cin >> num;
cout << "The fibonacci series: ";
cout << Fib<num>() << endl;
return 0;
int n;
cin>>n;
cout<<fib(n);
return 0;
}

0 comments on commit b9db699

Please sign in to comment.