/* Laura Toma csci107 Write a recursive method fib that computes the nth Fibonacci numbers (fib(n)). The Fibonacci numbers are defined as follows: fib(0) = 0 fib(1) = 1 fib(n) = fib(n-1) + fib(n-2) if n>1 Suggested test inputs (correct answer after arrow): fib(0) => 0 fib(1) => 1 fib(2) => 1 fib(3) => 2 fib(4) => 3 fib(10) => 55 fib(20) => 6765 */ #include /* compute and return the n-th fibonacci number */ int fibonacci(int n) { if (n < 0) { cout << "oops. must be positive.." << endl; exit(1); } if (n == 0) return 0; if (n == 1) return 1; //note that it can ONLY get here if n != 0 AND n != 1, so we dont //need an 'else'.. return fibonacci(n-1) + fibonacci(n-2); } int main() { int n; cout << "n="; cin >> n; cout << "fib(" << n << ")=" << fibonacci(n) << endl; return 0; }