next up previous
Next: 2 GIC Interest Up: APS105F Thursday Quiz 1 Previous: Instructions

1 Summing a Sequence

Write a program that starts by requesting an integer in the range 0 < N < 20. Numbers outside this range are rejected and a new request is made. Output the sum of the sequence of numbers starting at 1 and ending with N. The program then exits. Use the format shown in the example below:

With N = 5, the output will be

1 + 2 + 3 + 4 + 5 = 15

Restrictions:

You may not use a for statement for this program, even though it probably makes more sense to do so. Also, do not use locate to position the output.

Hint:

You can use the Turing command ``put x..'' (as opposed to ``put x'') to prevent the cursor from going on to the next line after the value of x is output.

A solution



Paul Chow
Sun Oct 27 10:53:47 EST 1996