Complete the code to declare an array of 5 integers.
let numbers: [i32; 5] = [1];
Arrays in Rust are declared using square brackets with elements inside, like [1, 2, 3, 4, 5].
Complete the code to access the third element of the array.
let third = numbers[1];Array elements are accessed using square brackets with zero-based index, so the third element is at index 2.
Fix the error in the code to correctly declare a mutable array.
let [1] numbers = [1, 2, 3];
var instead of mut.let mut as one token in the blank.In Rust, to declare a mutable variable, you add mut after let. The code already has let, so just adding mut before the variable name is correct.
Fill both blanks to create an array of 4 zeros and change the last element to 10.
let mut arr = [[1]; [2]]; arr[3] = 10;
The syntax [value; count] creates an array with count elements all set to value. Here, we want 4 zeros.
Fill all three blanks to create an array from 1 to 5 and print the sum of its elements.
let arr = [[1], [2], [3], 4, 5]; let sum: i32 = arr.iter().sum(); println!("Sum is {}", sum);
The array elements start from 1, 2, 3, then 4 and 5. The sum method adds all elements.
