Skip to content

Instantly share code, notes, and snippets.

@olarclara
Created April 13, 2017 15:29
Show Gist options
  • Save olarclara/11db1bdb0046fcb6429c89c9c570662f to your computer and use it in GitHub Desktop.
Save olarclara/11db1bdb0046fcb6429c89c9c570662f to your computer and use it in GitHub Desktop.
function recursiveFibonacci(n) {
if (n <= 1) {
return n;
}
else {
return recursiveFibonacci(n-1) + recursiveFibonacci(n-2);
}
}
function iterativeFibonacci(n) {
int x = 0, y = 1, z = 1;
for (int i = 0; i < n; i++) {
x = y;
y = z;
z = x + y;
}
return x;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment