Bird
0
0
DSA Cprogramming~10 mins

Array Traversal Patterns 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 print all elements of the array using a for loop.

DSA C
int arr[] = {1, 2, 3, 4, 5};
int n = 5;
for (int i = 0; i [1] n; i++) {
    printf("%d ", arr[i]);
}
Drag options to blanks, or click blank then click option'
A<=
B<
C>
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= causes out-of-bounds access.
Using > or >= will not enter the loop.
2fill in blank
medium

Complete the code to traverse the array backwards and print elements.

DSA C
int arr[] = {10, 20, 30, 40, 50};
int n = 5;
for (int i = n - 1; i [1] 0; i--) {
    printf("%d ", arr[i]);
}
Drag options to blanks, or click blank then click option'
A<=
B>
C>=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using > excludes the first element at index 0.
Using < or <= will not work for backward traversal.
3fill in blank
hard

Fix the error in the code to correctly print every second element starting from the first.

DSA C
int arr[] = {5, 10, 15, 20, 25, 30};
int n = 6;
for (int i = 0; i [1] n; i += 2) {
    printf("%d ", arr[i]);
}
Drag options to blanks, or click blank then click option'
A<
B<=
C>=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= causes out-of-bounds access.
Using > or >= will not enter the loop.
4fill in blank
hard

Fill both blanks to create a loop that prints elements at odd indices only.

DSA C
int arr[] = {2, 4, 6, 8, 10, 12};
int n = 6;
for (int i = [1]; i [2] n; i += 2) {
    printf("%d ", arr[i]);
}
Drag options to blanks, or click blank then click option'
A1
B0
C<
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Starting at 0 prints even indices.
Using <= causes out-of-bounds access.
5fill in blank
hard

Fill all three blanks to create a loop that prints elements divisible by 3.

DSA C
int arr[] = {3, 5, 6, 7, 9, 12};
int n = 6;
for (int i = 0; i [1] n; i++) {
    if (arr[i] [2] 3 == 0) {
        printf("%d ", arr[[3]]);
    }
}
Drag options to blanks, or click blank then click option'
A<
B%
Ci
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= causes out-of-bounds access.
Using / instead of % for divisibility.
Printing arr[i+1] or wrong index.