EasyManua.ls Logo

Commodore PET - Addition

Commodore PET
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...
ADDITION
This section
will
demonstrate how both the numeric string and multiple in-
teger techniques add
two
integer numbers larger than nine digits in length.
80th
the augend and addend must
be
positive integer numbers. The augend
is
the first
number in the equation. and the
addend
is
the second number. to be added to the
first.
Method 1: Addition via Numeric Strings
The steps involved are:
1.
Input
the augend and addend
as
two
positive numeric strings.
2.
Right
justify
the strings.
3.
Add the corresponding digits of the strings separately. including carry.
4.
Concatenate the answer into a one-string
resu
It.
5.
Print the answer string.
Let
us
examine each step in turn.
Step 1: Input the augend and addend
as
positive numeric strings
with
an
INPUT statement.
Screen Display
10
PRINTI:ltiltelteRDDITIONlteltelte":PRINT
2(1
1
NPUT
R$.,
E$
RUN
?1234567890123456
??57943572
Representation of Memory Contents
A$
1112131415\6!7J8191011l213]4[5J6]
B$
15171914131517121
A$
is
the augend and B$
is
the addend. Both may initially exceed the
9-digit
length
limit
with
the INPUT statement. For
simplicity
we
will
allow only positive
integer numbers to
be
input. Once vou are familiar
with
the basic concepts
of
the
addition program. vou may experiment and alter the program to allow for nega-
tive and fractional numbers.
Step 2: Right justify the strings. Bf!fore performing arithmetic operations.
the numbers should
be
right-justified because. in BASIC. alphabetic and numeric
strings are automatically left-justified.
If
the contents of numeric strings are added
without
first being right-justified. the answer
will
be
incorrect.
as
shown below:
190
Left Justified
Incorrect
1234567890123456
+~7943572
~028925090123456
Right Justified
Correct
1234567890123451
+
57943571
1234565948067021

Table of Contents

Related product manuals