tinycc/examples/ex3.c

25 lines
390 B
C
Raw Normal View History

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