Exerpad
🔥0
0 XP
Lv.1 Beginner
Log In

Sum 1 to N

Use a for loop to add up all the numbers from 1 to 100 and print the result.

Expected output:

text
Sum: 5050

Hints:

  • Create a let mut sum = 0; variable before the loop
  • Use for i in 1..=100 to loop through all the numbers
  • Add each number to sum inside the loop
  • Print the result after the loop with println!("Sum: {}", sum);
rust
fn main() {
}