Skip to content

Instantly share code, notes, and snippets.

@scvalex
Created December 18, 2012 13:25
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save scvalex/4327957 to your computer and use it in GitHub Desktop.
A segfaulting program to calculate Fibonacci numbers.
#include <stdio.h>
int fib(int n) {
int f1 = fib(n - 1);
int f2 = fib(n - 2);
if (n <= 2)
return 1;
return f1 + f2;
}
int main(int argc, char *argv[]) {
printf("The 4th Fibonacci number is %d\n", fib(4));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment