TheAlgorithms/C++
1.0.0
All the algorithms implemented in C++
Loading...
Searching...
No Matches
fibonacci_bottom_up.cpp
1
#include <iostream>
2
using namespace
std;
3
int
fib(
int
n) {
4
int
res[3];
5
res[0] = 0;
6
res[1] = 1;
7
for
(
int
i = 2; i <= n; i++) {
8
res[2] = res[1] + res[0];
9
res[0] = res[1];
10
res[1] = res[2];
11
}
12
return
res[1];
13
}
14
int
main
(
int
argc,
char
const
*argv[]) {
15
int
n;
16
cout <<
"Enter n: "
;
17
cin >> n;
18
cout <<
"Fibonacci number is "
;
19
cout << fib(n) <<
endl
;
20
return
0;
21
}
main
int main()
Main function.
Definition
generate_parentheses.cpp:110
endl
#define endl
Definition
matrix_exponentiation.cpp:36
dynamic_programming
fibonacci_bottom_up.cpp
Generated by
1.12.0