0
0
DSA Cprogramming~10 mins

Fibonacci Using DP in DSA C - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to initialize the first two Fibonacci numbers in the array.

DSA C
int fib[100];
fib[0] = 0;
fib[1] = [1];
Drag options to blanks, or click blank then click option'
A1
B2
C0
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Setting fib[1] to 0 instead of 1.
Using a number greater than 1 for fib[1].
2fill in blank
medium

Complete the for loop header to iterate from 2 to n.

DSA C
for (int i = [1]; i <= n; i++) {
    fib[i] = fib[i-1] + fib[i-2];
}
Drag options to blanks, or click blank then click option'
An
B2
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Starting loop from 0 or 1 causing overwriting of initial values.
Starting loop from n causing no iterations.
3fill in blank
hard

Fix the error in the return statement to return the nth Fibonacci number.

DSA C
return [1];
Drag options to blanks, or click blank then click option'
Afib[n]
Bfib[n+1]
Cfib[n-1]
Dfib[n-2]
Attempts:
3 left
💡 Hint
Common Mistakes
Returning fib[n-1] which is the previous Fibonacci number.
Returning fib[n+1] which is out of bounds.
4fill in blank
hard

Fill both blanks to complete the function header and declare the fib array size.

DSA C
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];
}
Drag options to blanks, or click blank then click option'
Aint
Bfloat
C50
D100
Attempts:
3 left
💡 Hint
Common Mistakes
Using float for n which is not suitable for indexing.
Declaring array size too small causing out of bounds.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps numbers to their Fibonacci values if the number is greater than 5.

DSA C
for (int [1] = 0; [1] <= [2]; [1]++) {
    if ([1] > 5) {
        fib[[1]] = fib[[1]-1] + fib[[1]-2];
    }
}
Drag options to blanks, or click blank then click option'
Ai
Bn
C10
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong loop variable names.
Incorrect loop range causing errors.