mirror of
https://github.com/KolibriOS/kolibrios.git
synced 2024-12-14 10:57:08 +03:00
b5e7b54c7a
git-svn-id: svn://kolibrios.org@6429 a494cfbc-eb01-0410-851d-a64ba20cac60
25 lines
390 B
C
25 lines
390 B
C
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
|
|
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, 2));
|
|
return 0;
|
|
}
|