5.14 · exercise
Sum from one to n
Write a loop that adds up every integer from 1 to n and prints the total.
The starter reads n and leaves a running total and a counter ready in registers. Fill in the loop so it adds each value from 1 through n into the total. The program already prints whatever the total register holds.
What is checked
- the total is printed on its own line
- the program exits cleanly
- the total is built up in the loop, not written in as a constant
- the same holds for other values of
nyou do not see; for 0 or a negativenthere is nothing to add, so the total is 0
specification
stdin10
stdoutprints the right output
exitexits with the right code
sourcedoes not hardcode the answer
hiddenright output and exit code on 5 more inputs you do not see
We run your program on the input above and on the hidden ones, and compare what it does. Nothing is matched against a stored solution.