Exerpad
🔥0
0 XP
Lv.1 Beginner
Log In

Fix the Accumulator

This code is supposed to calculate the product of numbers 1 through 5 (which is 1 x 2 x 3 x 4 x 5 = 120), but it has a bug!

Fix the code so it prints:

text
Product: 120

Hint: Look at the starting value of product and the operation inside the loop. Something isn't right!

rust
fn main() {
let mut product = 0;
let mut i = 1;
while i <= 5 {
product *= i;
i += 1;
}
println!("Product: {}", product);
}