Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the current element is zero.
DSA C#
if (matrix[i][j] [1] 0) { // mark row and column }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '==' causes assignment, not comparison.
Using '!=' checks for not equal, which is incorrect here.
✗ Incorrect
We use '==' to compare if matrix[i][j] equals zero.
2fill in blank
mediumComplete the code to mark the first element of the row as zero.
DSA C#
matrix[i][[1]] = 0;
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'i' or 'j' as column index instead of 0.
Using 1 instead of 0 for the first column.
✗ Incorrect
We mark the first column element (index 0) of the row as zero.
3fill in blank
hardFix the error in the loop condition to iterate over columns.
DSA C#
for (int j = 1; j [1] matrix[0].Length; j++) { if (matrix[0][j] == 0 || matrix[i][0] == 0) { matrix[i][j] = 0; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' causes out of bounds error.
Using '>' or '>=' causes loop to never run.
✗ Incorrect
Use '<' to iterate from 1 up to but not including matrix[0].Length.
4fill in blank
hardFill both blanks to correctly set the first row and first column zero flags.
DSA C#
bool firstRowZero = false; bool firstColZero = false; for (int i = 0; i < matrix.Length; i++) { if (matrix[i][[1]] == 0) firstColZero = true; } for (int j = 0; j < matrix[0].Length; j++) { if (matrix[[2]][j] == 0) firstRowZero = true; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 for first row or column.
Using last index instead of first.
✗ Incorrect
First column is index 0, first row is index 0.
5fill in blank
hardFill all three blanks to correctly zero out the first row and column if needed.
DSA C#
if (firstColZero) { for (int i = 0; i < matrix.Length; i++) { matrix[i][[1]] = 0; } } if (firstRowZero) { for (int j = 0; j < matrix[0].Length; j++) { matrix[[2]][j] = 0; } } // Final matrix state printed for (int i = 0; i < matrix.Length; i++) { for (int j = 0; j < matrix[0].Length; j++) { Console.Write(matrix[i][j] + " "); } Console.WriteLine(); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using last index instead of 0 for first row or column.
Using 1 instead of 0.
✗ Incorrect
First column and first row have index 0, so blanks are 0.
