Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare an integer array named numbers with 5 elements.
C
int [1][5];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name different from 'numbers'.
Forgetting the array size in the declaration.
✗ Incorrect
The correct way to declare an integer array named 'numbers' with 5 elements is
int numbers[5];.2fill in blank
mediumComplete the code to assign the value 10 to the third element of the array numbers.
C
numbers[[1]] = 10;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 3 as the index which is actually the fourth element.
Using 1 which is the second element.
✗ Incorrect
Array indices in C start at 0, so the third element is at index 2.
3fill in blank
hardFix the error in the code to correctly print the first element of the array numbers.
C
printf("%d", numbers[1]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of square brackets.
Using index 1 instead of 0.
✗ Incorrect
To access the first element of an array in C, use square brackets with index 0: numbers[0].
4fill in blank
hardFill both blanks to create a loop that prints all elements of the array numbers of size 5.
C
for(int [1] = 0; [2] < 5; [1]++) { printf("%d\n", numbers[[1]]); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in the loop parts.
Using a variable name not matching the one in the printf statement.
✗ Incorrect
The loop variable should be the same in initialization, condition, and increment. 'i' is commonly used.
5fill in blank
hardFill all three blanks to declare, initialize, and print the first element of an integer array arr with values 1, 2, 3.
C
int [1][] = [2]; printf("%d", [3][0]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for the array in declaration and print.
Incorrect array initialization syntax.
✗ Incorrect
Declare the array as 'int arr[] = {1, 2, 3};' and print the first element with 'arr[0]'.