From ad567cfc824f1e859d6c66ad1615fc31ff178f64 Mon Sep 17 00:00:00 2001 From: Gaminee <54733618+Gaminee@users.noreply.github.com> Date: Sat, 31 Oct 2020 03:24:07 +0530 Subject: [PATCH] Create fibonacci.cpp A program to find fibonacci series. --- fibonacci.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 fibonacci.cpp diff --git a/fibonacci.cpp b/fibonacci.cpp new file mode 100644 index 0000000..4f8dbfe --- /dev/null +++ b/fibonacci.cpp @@ -0,0 +1,26 @@ +#include +using namespace std; + +int Fib(int n) +{ + if (n == 0 || n == 1) + { + return n; + } + else { + return Fib(n-1) + Fib(n-2); + } +} + +int main(){ + int n,j=0; + cout << "Enter the total number of terms:"; + cin >> n; + + for(int i=1; i<=n; i++) + { + int r = Fib(j); + cout << r << " "; + j++; + } +}