Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to access the element at index 2 in the array.
DSA C#
int[] numbers = {1, 2, 3, 4, 5};
int value = numbers[[1]];
Console.WriteLine(value);Attempts:
3 left
💡 Hint
Common Mistakes
Using 3 as index instead of 2, which accesses the fourth element.
Confusing array indexes starting at 1 instead of 0.
✗ Incorrect
Index 2 in the array corresponds to the third element, which is 3.
2fill in blank
mediumComplete the code to update the element at index 1 to 10.
DSA C#
int[] numbers = {5, 6, 7, 8};
numbers[[1]] = 10;
Console.WriteLine(string.Join(", ", numbers));Attempts:
3 left
💡 Hint
Common Mistakes
Updating index 0 instead of 1.
Using an index out of range like 4.
✗ Incorrect
Index 1 is the second element, which we want to update to 10.
3fill in blank
hardFix the error in the code to correctly update the last element of the array.
DSA C#
int[] numbers = {9, 8, 7};
numbers[[1]] = 0;
Console.WriteLine(string.Join(", ", numbers));Attempts:
3 left
💡 Hint
Common Mistakes
Using index 3 which is out of bounds.
Using negative index which is invalid in C# arrays.
✗ Incorrect
The last element is at index 2 because array indexes start at 0.
4fill in blank
hardFill both blanks to access and update the middle element of the array.
DSA C#
int[] numbers = {4, 5, 6, 7, 8};
numbers[[1]] = [2];
Console.WriteLine(string.Join(", ", numbers));Attempts:
3 left
💡 Hint
Common Mistakes
Using index 3 instead of 2 for the middle element.
Assigning the wrong value to the element.
✗ Incorrect
Index 2 is the middle element in a 5-element array, and we update it to 10.
5fill in blank
hardFill all three blanks to create an array, update an element, and print the updated array.
DSA C#
int[] [1] = {1, 2, 3, 4}; [1][[2]] = 100; Console.WriteLine(string.Join(", ", [1]));
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Updating the wrong index.
✗ Incorrect
We declare the array named 'nums', update index 2, and print 'nums'.
