7-9
Application to
Tabular
Calculations
Vertical and horizontal tabular calculations
as
shown below are frequently
required in practical calculations. Although this type
of
calculation was carried
out using the array (see page 66), tabular calculations can be simplified further
by considering the DATA BANK
as
being one large table.
~
Product A Product B
Product C
Product D
Horizontal
total
Branch X 5329
4280
3602 2310
Branch Y
2682 6313
4203 1128
Branch Z
5113
3229
5176
965
Vertical to ta!
• Outline
of
the Program
Since' the size
of
the table will be requested when this program
is
executed, enter
the number
of
horizontal items (m) and then the number
of
vertical items (n).
Enter data; one column at a time vertically from the top.
"Calculation"
is
dis-
played and calculation starts after all data are input. When calculation
is
over,
the results are displayed in the order
of
vertical total and horizontal total.
• Program List
10
BEEP
IN
PUT
" ( m x
n)
" , A, B :
ERAS
E
F:
DIM
F(A+1,B+1)
20
FOR
C=1
TO
A
30
FOR
0=1
TO
B
40
PRINT
"(";C;"
\";
D;")";
50
BEEP INPUT
F(C,D>
60
$
="N
"+
STR$(0)+","+
STR$(F(C,0))
70
IF
A=C
THEN
$=
$+",0"
80
WRITE:t:I=
$
90
NEXT
D
100
WRITE:t:I=
"M"+
STR$(C)+",0"
110
NEXT
C
120
PRINT
"Calculation";
140
FOR
C=1
TO
B+1
150
F(A+1,C>=0
197