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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/rust/collections_and_data_structures/arrays.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics