Created
September 4, 2017 19:36
-
-
Save tnarek/32be791ba9a8455c3c0a38663784487e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| int fib_rec2(int n, int &prev1, int &prev2) { | |
| if (n < 3) { | |
| prev1 = 1; | |
| prev2 = 0; | |
| return 1; | |
| } | |
| int prev3; | |
| int prev4; | |
| prev2 = fib_rec2(n - 2, prev3, prev4); | |
| prev1 = fib_rec2(n - 1, prev2, prev3); | |
| return prev1 + prev2; | |
| } | |
| int main() { | |
| int a, b; | |
| cout << fib_rec2(3, a, b); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment