Created
August 12, 2012 13:02
-
-
Save jbochi/3331737 to your computer and use it in GitHub Desktop.
Fibonnaci in C for dailykata.net
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) { | |
if (n == 1) { | |
return 1; | |
} else if (n == 0) { | |
return 0; | |
} else { | |
return fib(n - 1) + fib(n - 2); | |
} | |
} | |
int main() { | |
int i; | |
for (i = 0; i < 10; i++) { | |
printf("fib %d: %d\n", i, fib(i)); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment