Created
August 12, 2012 09:20
-
-
Save felipernb/3330823 to your computer and use it in GitHub Desktop.
Fibonacci in C
This file contains 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
//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