From 973250d44798d5682e6190a5250d8738779d15fb Mon Sep 17 00:00:00 2001 From: Pritam Negi Date: Sun, 4 Oct 2020 09:20:41 +0530 Subject: [PATCH] Added code for getting nth fibonacci number in C++ --- CPP/nth_fibonacci_number.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 CPP/nth_fibonacci_number.cpp diff --git a/CPP/nth_fibonacci_number.cpp b/CPP/nth_fibonacci_number.cpp new file mode 100644 index 0000000..ffa428e --- /dev/null +++ b/CPP/nth_fibonacci_number.cpp @@ -0,0 +1,24 @@ +#include +using namespace std; +int fib(int n) +{ + int a = 0, b = 1, c, i; + if( n == 0) + return a; + for (i = 2; i <= n; i++) + { + c = a + b; + a = b; + b = c; + } + return b; +} + +int main () +{ + int n; + cout<<"Enter the term you want to get: "; + cin>>n; + cout<<"The fibonacci number is: "<