testsuite/systemtap.context/fib.c
raw| 1 | #include <stdlib.h> |
| 2 | #include <stdio.h> |
| 3 | |
| 4 | long fib(int x) |
| 5 | { |
| 6 | if (x == 0 || x == 1) |
| 7 | return 1; |
| 8 | else |
| 9 | return fib(x - 1) + fib(x - 2); |
| 10 | } |
| 11 | |
| 12 | int main(int argc, char **argv) |
| 13 | { |
| 14 | int x = 0; |
| 15 | long result = 0; |
| 16 | |
| 17 | if (argc != 2) |
| 18 | { |
| 19 | printf("0\n"); |
| 20 | return 1; |
| 21 | } |
| 22 | x = atoi(argv[1]); |
| 23 | if (x < 0) |
| 24 | { |
| 25 | printf("0\n"); |
| 26 | return 1; |
| 27 | } |
| 28 | result = fib(x); |
| 29 | printf("%ld\n", result); |
| 30 | return 0; |
| 31 | } |