Exerpad
🔥 0
0 XP
Exercise 7 · Chapter: Closures & IteratorsRequired+50 XP

Fold Product

Use .fold() to calculate the product of all numbers in vec![2, 3, 4]. Start with 1 as the initial value.

Expected output:

Product: 24

Hints:

  • .fold(1, |acc, x| acc * x) starts with 1 and multiplies each item
  • acc is the accumulator (running total), x is the current item
rust
fn main() {
}
Output
Run your code to see the output here.