Skip to content

Instantly share code, notes, and snippets.

@mumumu
Created January 30, 2011 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mumumu/803015 to your computer and use it in GitHub Desktop.
Save mumumu/803015 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
static unsigned int fib(int param)
{
assert(param > 0);
int f1, f2, f3 = 0;
int i;
for (i = 1; i <= param; i++) {
if (i == 1 || i == 2) {
f1 = 0;
f2 = 1;
}
f3 = f2 + f1;
f1 = f2;
f2 = f3;
}
return f3;
}
int main(int argc, char *argv[]) {
// No Error Processing
printf("%u", fib(atoi(argv[1])));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment