Rust Program: Iterate over vector of integers
Write a Rust program that iterates over a vector of integers and prints each element.
Sample Solution:
Rust Code:
Output:
100 200 300 400 500
Explanation:
In the exercise above,
- Define a vector 'numbers' containing integers.
- Use a "for" loop to iterate over each element of the vector.
- Within the loop, we print each element using "println!()".
Rust Code Editor:
Previous: Rust Iterators and Iterator Adapters Exercises.
Next: Rust Program: Calculate sum of range of numbers.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.