From 7dadd8a60537f43bfc3650cf4f83c17bb993f77b Mon Sep 17 00:00:00 2001 From: Gaminee <54733618+Gaminee@users.noreply.github.com> Date: Sat, 31 Oct 2020 03:13:23 +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++; + } +}