Skip to content

Instantly share code, notes, and snippets.

@tnarek
Created September 4, 2017 19:36
Show Gist options
  • Select an option

  • Save tnarek/32be791ba9a8455c3c0a38663784487e to your computer and use it in GitHub Desktop.

Select an option

Save tnarek/32be791ba9a8455c3c0a38663784487e to your computer and use it in GitHub Desktop.
#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