From 4f907dab88a53b9e4c536d37828c031bf3e58a01 Mon Sep 17 00:00:00 2001 From: Parth mahajan Date: Sun, 13 Oct 2019 15:32:07 +0530 Subject: [PATCH] fibonaci recursive --- fibonacci.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 fibonacci.cpp diff --git a/fibonacci.cpp b/fibonacci.cpp new file mode 100644 index 0000000..9c0394d --- /dev/null +++ b/fibonacci.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; + +long fib(int n) +{ + if(n==1) + return 0; + else if(n==2) + return 1; + else + { + return fib(n-1)+fib(n-2); + } +} +int main() +{ + long x; + printf("enter x: "); + scanf("%ld",&x); + printf("%d",fib(x)); +}