Skip to content

Instantly share code, notes, and snippets.

@jleeothon
Created January 17, 2015 22:06
Show Gist options
  • Save jleeothon/2a5941665d9ca608d747 to your computer and use it in GitHub Desktop.
Save jleeothon/2a5941665d9ca608d747 to your computer and use it in GitHub Desktop.
unsigned int fibonacci(unsigned int n) {
if (n > 2) {
unsigned int a = 1, b = 1;
while (n-- > 2) {
b = a + b;
a = b - a;
}
return b;
} else if (n) {
return 1;
} else {
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment