Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to access the first element of the array.
C Sharp (C#)
int[] numbers = {1, 2, 3, 4};
int first = numbers[[1]]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 as the first index instead of 0.
Using a negative index which is invalid.
✗ Incorrect
Arrays in C# start at index 0, so the first element is at index 0.
2fill in blank
mediumComplete the code to access the last element of the array using its length.
C Sharp (C#)
int[] values = {10, 20, 30, 40, 50};
int last = values[values.Length [1] 1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using +1 which causes an index out of range error.
Using multiplication or division instead of subtraction.
✗ Incorrect
The last element is at index Length - 1 because indexing starts at 0.
3fill in blank
hardFix the error in accessing the third element of the array.
C Sharp (C#)
string[] fruits = {"apple", "banana", "cherry"};
string third = fruits[[1]]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 3 as index which is out of range.
Using 1 or 0 which points to earlier elements.
✗ Incorrect
The third element is at index 2 because indexing starts at 0.
4fill in blank
hardFill both blanks to create an array of squares for numbers 1 to 5.
C Sharp (C#)
int[] squares = new int[5]; for (int i = 0; i [1] 4; i++) { squares[i] = (i [2] 1) * (i [2] 1); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of <= causes missing the last element.
Subtracting 1 instead of adding 1 changes the numbers incorrectly.
✗ Incorrect
The loop runs while i is less than or equal to 4 (indexes 0 to 4). To get numbers 1 to 5, add 1 to i before squaring.
5fill in blank
hardFill all three blanks to create a reversed copy of the array.
C Sharp (C#)
int[] original = {1, 2, 3, 4};
int[] reversed = new int[original.Length];
for (int [1] = 0; [1] < original.Length; [1]++) {
reversed[[2]] = original[original.Length [3] 1 - [1]];
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong loop variable names inconsistently.
Incorrect calculation of reversed index causing errors.
✗ Incorrect
Use 'i' as the loop variable. Assign reversed[i] to original at the reversed index calculated by Length - 1 - i.