fib fix (grischka)
This commit is contained in:
parent
c897c52088
commit
6144d43321
1 changed files with 23 additions and 23 deletions
|
|
@ -1,23 +1,23 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int fib(n)
|
int fib(n)
|
||||||
{
|
{
|
||||||
if (n <= 2)
|
if (n <= 2)
|
||||||
return 1;
|
return 1;
|
||||||
else
|
else
|
||||||
return fib(n-1) + fib(n-2);
|
return fib(n-1) + fib(n-2);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
printf("usage: fib n\n"
|
printf("usage: fib n\n"
|
||||||
"Compute nth Fibonacci number\n");
|
"Compute nth Fibonacci number\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
n = atoi(argv[1]);
|
n = atoi(argv[1]);
|
||||||
printf("fib(%d) = %d\n", n, fib(n, 2));
|
printf("fib(%d) = %d\n", n, fib(n));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue