Skip to content

Commit 3f0046b

Browse files
authored
Merge pull request kelvins#270 from metacoder87/patch-5
Update and rename Fibonacci.cpp to FibonacciIterative.cpp
2 parents 0197303 + 314fea9 commit 3f0046b

File tree

2 files changed

+22
-39
lines changed

2 files changed

+22
-39
lines changed

src/cpp/Fibonacci.cpp

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/cpp/FibonacciIterative.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
#include <iostream>
3+
4+
using namespace std;
5+
6+
int fibonacciIterative(int n)
7+
{
8+
int last = 0;
9+
int curr = 1;
10+
for (int index = 0; index < n; ++index)
11+
{
12+
int temp = curr;
13+
curr += last;
14+
last = temp;
15+
}
16+
return last;
17+
}
18+
19+
int main()
20+
{
21+
cout << fibonacciIterative(12) << endl;
22+
}

0 commit comments

Comments
 (0)