006-001-007
for Loop: Sum from 1 to 10
Easy
Problem Description
for loop: Sum from 1 to N
In this problem, you will create a program that reads an integer N from standard input, uses a for loop to sequentially add integers from 1 to N, and displays the total to standard output.
Learning Objective: Understand repetitive processing and cumulative calculation using for loops
Overview
Create a program that reads an integer N, uses a for loop to calculate the sum of integers from 1 to N, and outputs the result.
Specifications
- Read integer N from standard input
- Use a for loop to iterate through numbers 1 to N
- Accumulate each number
- Output the final sum
Input Format
N
- N: A positive integer (upper bound for summation)
Output Format
Sum: total
Examples
| Input | Output |
|---|---|
| 10 | Sum: 55 |
| 5 | Sum: 15 |
Note
For example, when N=10: 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = 55
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up