Complete the code to initialize the first two Fibonacci numbers in the array.
int fib[100]; fib[0] = 0; fib[1] = [1];
The first two Fibonacci numbers are 0 and 1. So fib[1] should be 1.
Complete the for loop header to iterate from 2 to n.
for (int i = [1]; i <= n; i++) { fib[i] = fib[i-1] + fib[i-2]; }
The loop starts from 2 because the first two Fibonacci numbers are already set.
Fix the error in the return statement to return the nth Fibonacci number.
return [1];
The nth Fibonacci number is stored at fib[n].
Fill both blanks to complete the function header and declare the fib array size.
int fibonacci([1] n) { int fib[[2]]; fib[0] = 0; fib[1] = 1; for (int i = 2; i <= n; i++) { fib[i] = fib[i-1] + fib[i-2]; } return fib[n]; }
The function parameter should be an integer 'int n'. The array size should be large enough, here 100.
Fill all three blanks to create a dictionary comprehension that maps numbers to their Fibonacci values if the number is greater than 5.
for (int [1] = 0; [1] <= [2]; [1]++) { if ([1] > 5) { fib[[1]] = fib[[1]-1] + fib[[1]-2]; } }
The loop variable is i, iterating from 0 to n (which can be 10). The condition checks if i > 5.