TheAlgorithms-C-Plus-Plus/dynamic_programming/Fibonacci_Bottom_Up.cpp
Christian Clauss 5c241487aa
rename Dynamic Programming -> dynamic_programming (#645)
* rename Dynamic Programming -> dynamic_programming

* rename dynamic-programming -> dynamic_programming
2019-11-28 13:29:01 +01:00

25 lines
375 B
C++

#include <bits/stdc++.h>
using namespace std;
int fib(int n)
{
int res[3];
res[0] = 0;
res[1] = 1;
for (int i = 2; i <= n; i++)
{
res[2] = res[1] + res[0];
res[0] = res[1];
res[1] = res[2];
}
return res[1];
}
int main(int argc, char const *argv[])
{
int n;
cout << "Enter n: ";
cin >> n;
cout << "Fibonacci number is ";
cout << fib(n) << endl;
return 0;
}