A segfaulting program to calculate Fibonacci numbers.
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
#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