ex3.c 371 B

123456789101112131415161718192021222324
  1. #include <tcclib.h>
  2. int fib(n)
  3. {
  4. if (n <= 2)
  5. return 1;
  6. else
  7. return fib(n-1) + fib(n-2);
  8. }
  9. int main(int argc, char **argv)
  10. {
  11. int n;
  12. if (argc < 2) {
  13. printf("usage: fib n\n"
  14. "Compute nth Fibonacci number\n");
  15. return 1;
  16. }
  17. n = atoi(argv[1]);
  18. printf("fib(%d) = %d\n", n, fib(n, 2));
  19. return 0;
  20. }