Write a loop that sums numbers 1 through 10. Initialize a sum variable to 0 before the loop, then add each number to the sum inside the loop body. Solution: int sum = 0; for (int i = 1; i <= 10; i++) { sum += i; } cout << sum; prints 55, which is the sum of integers from 1 to 10.
The accumulator pattern starts with zero and adds each value during iteration. You can sum any range by changing the loop bounds, or use this pattern to sum user input.