From 1b4a6df37518615538a07b2849266750404a7541 Mon Sep 17 00:00:00 2001 From: priyal bhatewara <47683250+priyalbhatewara123@users.noreply.github.com> Date: Fri, 2 Oct 2020 16:10:02 +0530 Subject: [PATCH] Find nth term in fibonacci series using recursion --- .../fibonacci/cpp/fibonacciUsingRecursion.cpp | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Mathematics/fibonacci/cpp/fibonacciUsingRecursion.cpp diff --git a/Mathematics/fibonacci/cpp/fibonacciUsingRecursion.cpp b/Mathematics/fibonacci/cpp/fibonacciUsingRecursion.cpp new file mode 100644 index 000000000..c14ee9ee1 --- /dev/null +++ b/Mathematics/fibonacci/cpp/fibonacciUsingRecursion.cpp @@ -0,0 +1,26 @@ +/* +Problem Statement: +Find nth term in fibonacci series using recursion +*/ + +#include +using namespace std; + +int fibonacci(int n) { + + //base case + if (n == 0 or n == 1) { + return n; + } + + return (fibonacci(n - 1) + fibonacci(n - 2)); +} + + +int main() { + + int n; cin >> n; + cout << fibonacci(n); + + return 0; +} \ No newline at end of file