tinycc/win32/examples/fib.c

25 lines
343 B
C
Raw Normal View History

2005-04-17 17:10:22 +04:00
#include <stdio.h>
#include <stdlib.h> // atoi()
2005-04-17 17:10:22 +04:00
int fib(n)
{
if (n <= 2)
return 1;
else
return fib(n-1) + fib(n-2);
}
int main(int argc, char **argv)
{
int n;
if (argc < 2) {
printf("usage: fib n\n"
"Compute nth Fibonacci number\n");
return 1;
}
n = atoi(argv[1]);
printf("fib(%d) = %d\n", n, fib(n));
return 0;
}