EasyManua.ls Logo

Commodore CBM - Page 214

Commodore CBM
447 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Step 4: The
la
st step before printing
is
to concatenate the
two
sums
into
one answer by linking CH$ to the front of
CL$.
The preceding space and carry D
are truncated from CL$ by selecting the rightmost eight digits from that string
(see
the previous discussion of Numeric Strings for further explanation of this
methodl.
1100
C$=CH$+RIGHT$(CL$,F)
C$=CH$11i11121314151617191
+
RIGHT$(CL$11i1114IsloI6l71012ISL8l
C$-11i11121314151617191
+
141sIol61710121s1
C$-11i111213141516171914lsI016171012Isl
Step 5: Print the answer C$.
1110
PRINT:PRINT"ANSWER=";C$:PRINT
The program
is
now
complete. In summary, this Multiple Integer Addition
program accepts
two
positive integer numbers
up
to
16
digits long, divides
them into high and
low
segments of eight digits each,
and
adds
the corres-
ponding high segments and
low
segments. The
two
su
ms are then concate-
nated into a single string answer
with
a maximum length of 17 digits. This
Multiple Integer Addition program allows
Vou
eight more digits than the PETs
built-in maximum. yielding greater accuracy and much more flexibility.
Below
is
the listing of the program
with
a sample
run.
Vou may wish to
amend this program or create your
own
to allow for decimal or negative numbers.
Add high strings
Add high and
low
answers
Add low strings
11'::
140
1
Separate
A$
and
S$
Into parts:
high and low
}
}
1
€1
PF.:
1
tH"
::'}+:i+;i+;i1UL
TI
PLE
1
HTEGER
AIID
1T1
ONi+;i+;i+;"
:
PR
1
tH
2f1
HJPUT
A$,
B$
Input
numeric strings
1000
X=LEN(A$):Y=LEN(B$) l
1002
IF
X>Y
THEN
F=X/2:GOTO
1006
11'::104
F='T'/2 Set divider point. F
1006
IF
F>INT(F)
THEN
F=INT(F)+l
1008
F$=LEFT$(ZERO$,F)
1010
IF
X(=F
THEN
AH=0:AL=VAL(A$):GOTO
1020
AH=VAL(LEFT$(A$,X-F»
1030
AL=VAL(RIGHT$(A$,F»
1040
IF
Y(=F
THEN
BL=VAL(B$):GOTO
1€170
1050
BH=VAL(LEFT$(B$,Y-F»
1060
BL=VAL(RIGHT$(B$,F»
1070
CL$=STR$(AL+BL)
1075
CL$=MID$(CL$,2,LEN(CL$)-1)
1080
IF
LEN(CL$»F
THEN
I1=1
1090
CH$=STR$(AH+BH+I1)
1095
CH$=MID$(CH$,2,LEN(CH$)-1)
111'::10
C$=CH$+CL$
1110
PRHJT'
PRHH"At·JS~'JER=".;
C$:
PF.:HH
Print answer
1120
AH=0:
AL=fl
:
E:H=l'::l
:
E:L=I~1
:rl=fl :CH$=" " :CL$="" C$="'"
GOTO
213
1130
ENII
201

Table of Contents

Other manuals for Commodore CBM

Related product manuals