w3resource

Rust Arrays Exercises with Solutions and Explanations

Rust Arrays Exercises [10 exercises with solution and Explanation]

[An editor is available at the bottom of the page to write and execute the scripts. Go to the editor]

1. Write a Rust program to create an array of integers with size 7 and initialize it with values 1, 2, 3, 4, 5, 6 and 7. Print the array.

Click me to see the solution

2. Write a Rust program to create an array of integers with size 9 and initialize it with any value. Access and print the element at index 7.

Click me to see the solution

3. Write a Rust program to create an array of characters with size 6 and initialize it with the characters 'A', 'B', 'C', 'D', 'E', and 'F'. Update the element at index 3 to 'P' and print the updated array.

Click me to see the solution

4. Write a Rust program to create an array of integers with size 7 and initialize it with random values. Calculate and print the sum of all the elements in the array.

Click me to see the solution

5. Write a Rust program to create an array of integers with size 7 and initialize it with random values. Search for a specific value in the array and print whether it exists or not.

Click me to see the solution

6. Write a Rust program to create an array of integers with size 9 and initialize it with random values. Filter out even numbers from the array and print the resulting array.

Click me to see the solution

7. Write a Rust program to create an array of integers with size 5 and initialize it with random values. Map each element of the array to its square and print the resulting array.

Click me to see the solution

8. Write a Rust program to create an array of characters with size 7 and initialize it with random characters. Reverse the elements of the array and print the reversed array.

Click me to see the solution

9. Write a Rust program to create two arrays of integers, each with size 4, and initialize them with random values. Concatenate the two arrays and print the resulting array.

Click me to see the solution

10. Write a Rust program to create an array of integers with size 10 and initialize it with random values. Sort the array in ascending order and print the sorted array.

Click me to see the solution

Rust Code Editor:

More to Come !

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.



Follow us on Facebook and Twitter for latest update.