Exercise 5 · Chapter: Closures & IteratorsRequired+50 XP
Sum All
Use .iter().sum() to calculate the sum of vec![10, 20, 30, 40].
Expected output:
Total: 100
Hints:
let total: i32 = numbers.iter().sum();- You need the type annotation
: i32so Rust knows what type to sum into
rust
fn main() {
}
Output
Run your code to see the output here.