/* * Program to compute elements of the Fibonacci sequence using recursion. * * (not efficient, but simple!) */ #include int fibonacci(int n); int main(void) { int n; printf("enter n\n"); if (scanf("%d", &n) != 1) { printf("not number\n"); return 1; } if (n < 0) { printf("negative\n"); return 1; } printf("fibonacci(%d) is %d\n", n, fibonacci(n)); return 0; } int fibonacci(int n) { if (n <= 1) return 1; else return fibonacci(n-1) + fibonacci(n-2); }