Rust Iterator Exercises with Solutions and Explanations
Rust Iterators and Iterator Adapters Exercises [15 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 that iterates over a vector of integers and prints each element.
2. Write a Rust program that iterates over a range of numbers and calculates the sum of all numbers.
3. Write a Rust program that iterates over a vector of strings and prints the length of each string.
4. Write a Rust program that iterates over a vector of tuples (i32, i32) and calculates the product of the first and second elements of each tuple.
5. Write a Rust program that iterates over a vector of booleans and counts the number of false and true values.
6. Write a Rust program that iterates over a vector of floats and calculates the average value.
7. Write a Rust program that iterates over a vector of Option
8. Write a Rust program that iterates over a vector of arrays [i32; 2] and calculates the sum of the first and second elements of each array.
9. Write a Rust program that iterates over a range of numbers and filters out odd numbers.
10. Write a Rust program that iterates over a vector of strings and converts each string to uppercase.
11. Write a Rust program that iterates over a vector of integers and cubes for each element.
12. Write a Rust program that iterates over a vector of tuples (i32, i32) and swaps the elements of each tuple.
13. Write a Rust program that iterates over a vector of Option
14. Write a Rust program that iterates over a vector of arrays [i32; 2] and calculates the difference between the first and second elements of each array.
15. Write a Rust program that iterates over a range of numbers and checks if each number is prime. Return a new vector containing only prime numbers.
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.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics