Post Reply 
(12C) Digit Sum
01-08-2019, 08:24 AM
Post: #6
RE: (12C) Digit Sum
(01-08-2019 04:34 AM)Gamo Wrote:  Simple straight forward approach for Digit Sum

For a slightly different approach:
Code:
01-    44 0    STO 0
02-       1    1
03-       0    0
04-      10    ÷
05-   43 25    INTG
06-   43 35    x=0
07-43,33 14    GTO 14
08-       9    9
09-      34    x<>y
10-      20    ×
11- 44 30 0    STO- 0
12-   43 36    LSTx
13-43,33 02    GTO 02
14-    45 0    RCL 0

Example:

4711
R/S
13


The program calculates: 4711 - 9×471 - 9×47 - 9×4 = 13

Or a bit longer without use of registers:
Code:
01-      36    ENTER
02-      36    ENTER
03-      35    CLx
04-      34    x<>y
05-       1    1
06-       0    0
07-      10    ÷
08-   43 25    INTG
09-   43 35    x=0
10-43,33 14    GTO 14
11-      40    +
12-   43 36    LSTx
13-43,33 05    GTO 05
14-      33    R↓
15-       9    9
16-      20    ×
17-      30    -

Here it calculates: 4711 - 9×(471 + 47 + 4) = 13


Cheers
Thomas

PS: Just noticed that x=0 doesn't enable stack-lift.
Is that well known?
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(12C) Digit Sum - Gamo - 05-03-2018, 10:50 AM
RE: (12C) Digit Sum - Dieter - 05-03-2018, 06:02 PM
RE: (12C) Digit Sum - Dieter - 05-04-2018, 12:11 PM
RE: (12C) Digit Sum - Gamo - 05-10-2018, 12:11 PM
RE: (12C) Digit Sum - Gamo - 01-08-2019, 04:34 AM
RE: (12C) Digit Sum - Thomas Klemm - 01-08-2019 08:24 AM



User(s) browsing this thread: 1 Guest(s)