Skip to content

Instantly share code, notes, and snippets.

@felipernb
Created August 12, 2012 09:20
Show Gist options
  • Save felipernb/3330823 to your computer and use it in GitHub Desktop.
Save felipernb/3330823 to your computer and use it in GitHub Desktop.
Fibonacci in C
//O(n) in time, O(1) in space
int fib(int n) {
int a, b, i, temp;
a = 0;
b = 1;
for (i = 0; i < n; i++) {
temp = a;
a = a + b;
b = temp;
}
return a;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment