Last change
on this file since 279 was 279, checked in by coas-nagasima, 7 years ago |
ファイルを追加、更新。
|
-
Property svn:eol-style
set to
native
-
Property svn:keywords
set to
Id
-
Property svn:mime-type
set to
text/x-csrc
|
File size:
390 bytes
|
Rev | Line | |
---|
[279] | 1 | #include <stdlib.h>
|
---|
| 2 | #include <stdio.h>
|
---|
| 3 |
|
---|
| 4 | int fib(n)
|
---|
| 5 | {
|
---|
| 6 | if (n <= 2)
|
---|
| 7 | return 1;
|
---|
| 8 | else
|
---|
| 9 | return fib(n-1) + fib(n-2);
|
---|
| 10 | }
|
---|
| 11 |
|
---|
| 12 | int main(int argc, char **argv)
|
---|
| 13 | {
|
---|
| 14 | int n;
|
---|
| 15 | if (argc < 2) {
|
---|
| 16 | printf("usage: fib n\n"
|
---|
| 17 | "Compute nth Fibonacci number\n");
|
---|
| 18 | return 1;
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | n = atoi(argv[1]);
|
---|
| 22 | printf("fib(%d) = %d\n", n, fib(n, 2));
|
---|
| 23 | return 0;
|
---|
| 24 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.