tinycc/examples/ex3.c

24 lines
371 B
C
Raw Normal View History

#include <tcclib.h>
2003-10-05 05:25:32 +08:00
int fib(n)
{
if (n <= 2)
return 1;
else
return fib(n-1) + fib(n-2);
}
2009-04-18 20:31:35 +08:00
int main(int argc, char **argv)
2003-10-05 05:25:32 +08:00
{
int n;
if (argc < 2) {
printf("usage: fib n\n"
"Compute nth Fibonacci number\n");
return 1;
}
2009-04-18 20:31:35 +08:00
2003-10-05 05:25:32 +08:00
n = atoi(argv[1]);
printf("fib(%d) = %d\n", n, fib(n, 2));
return 0;
}