Skip to content

Instantly share code, notes, and snippets.

@mina86
Forked from rsayers/fib.c
Created January 16, 2010 22:21
Show Gist options
  • Save mina86/279048 to your computer and use it in GitHub Desktop.
Save mina86/279048 to your computer and use it in GitHub Desktop.
#include <stdio.h>
static unsigned long count;
static unsigned long fib(unsigned n) {
++count;
return n > 1 ? fib(n - 1) + fib(n - 2) : n;
}
int main(void) {
unsigned i;
for (i = 0; i < 36; ++i) {
unsigned long ans;
count = 0;
ans = fib(i);
printf("%2u: %10u (%10u calls)\n", i, ans, count);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment