diff options
Diffstat (limited to 'targets/instr_fib.c')
| -rw-r--r-- | targets/instr_fib.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/targets/instr_fib.c b/targets/instr_fib.c new file mode 100644 index 0000000..9da9306 --- /dev/null +++ b/targets/instr_fib.c @@ -0,0 +1,12 @@ +// fib(n) the slow way: a call tree to draw. Exits with fib(argv[1]), by +// default fib(6). +#include <stdlib.h> + +static unsigned fib(unsigned n) { + if (n < 2) return n; + return fib(n - 1) + fib(n - 2); +} + +int main(int argc, char **argv) { + return (int)fib(argc > 1 ? (unsigned)atoi(argv[1]) : 6); +} |
