|
Section 4: Programming 165
|
|
Sample Case. Sum of First n Digits. Calculate the sum of 1 + 2 + 3 + . . . + n where n is
the x-register at the beginning.
|
|
Switch to W/PRGM.
|
|
Press fPRGM to clear memory.
|
|
Key in the following steps.
|
|
Keys
|
|
|
Comment
|
|
LBL A
|
|
|
|
|
STO 8
|
|
|
Preset n in R8.
|
|
fSTK
|
|
|
Clear stack.
|
|
LBL 1
|
|
|
Beginning of repeat segment.
|
|
RCL 8
|
|
|
Recall r8 to X.
|
|
+
|
|
|
Add to previous sum.
|
|
gDSZ
|
|
|
Decrement r8 (r8 — 1 R8)
and test for zero.
|
|
GTO 1
|
|
|
Repeat if r8 is not zero.
|
|
RTN
|
|
|
Stop after nth iteration.
|
|
|
Calculating the Function
|
|
Switch to RUN.
|
|
Press
|
|
See Displayed
|
|
Comment
|
|
5 A
|
|
|
|
Sum of 1 + 2 + . . . + 5.
|
|
20 A
|
|
|
|
Sum of 1 + 2 + . . . + 20.
|
|
25 A
|
|
|
|
Sum of 1 + 2 + . . . + 25.
|
|