From b9db699e6d2f5ed1408644c0ffb9343ff2756332 Mon Sep 17 00:00:00 2001 From: Tanuj Rohilla <33057694+TanujRohilla@users.noreply.github.com> Date: Mon, 1 Oct 2018 19:39:24 +0530 Subject: [PATCH] Update fibonacci.cpp --- fibonacci/fibonacci.cpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/fibonacci/fibonacci.cpp b/fibonacci/fibonacci.cpp index bbbc3d41..39b6adcc 100644 --- a/fibonacci/fibonacci.cpp +++ b/fibonacci/fibonacci.cpp @@ -1,16 +1,17 @@ -#include - -template int Fib(){ return Fib() + Fib(); } -template <> int Fib<1>() { return 1; } -template <> int Fib<0>() { return 1; } - +//Fibonacci Series using Recursion +#include 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() << endl; - return 0; + int n; + cin>>n; + cout<