Complete the code to return the base case value for n equals 0 in the Fibonacci function.
int fibonacci(int n) {
if (n == 0) {
return [1];
}
// other code
}The Fibonacci sequence starts with 0 for n=0, so the function should return 0 in this base case.
Complete the code to return the base case value for n equals 1 in the Fibonacci function.
int fibonacci(int n) {
if (n == 1) {
return [1];
}
// other code
}The Fibonacci sequence has 1 as the value for n=1, so the function should return 1 in this base case.
Fix the error in the recursive call to compute the Fibonacci number for n-1.
int fibonacci(int n) {
if (n == 0 || n == 1) {
return n;
}
return fibonacci([1]) + fibonacci(n - 2);
}The Fibonacci number for n is the sum of Fibonacci(n-1) and Fibonacci(n-2). The recursive call must use n-1.
Fill both blanks to complete the recursive Fibonacci function correctly.
int fibonacci(int n) {
if (n == 0 || n == 1) {
return n;
}
return fibonacci([1]) + fibonacci([2]);
}The Fibonacci function returns the sum of fibonacci(n-1) and fibonacci(n-2) for n > 1.
Fill all three blanks to create a complete recursive Fibonacci function with base cases and recursive calls.
int fibonacci(int n) {
if (n == [1] || n == [2]) {
return n;
}
return fibonacci([3]) + fibonacci(n - 2);
}The base cases are for n=0 and n=1, returning n. The recursive call uses n-1 and n-2.
