IBM 5110 Basic Introduction page 140

Table of Contents

Advertisement

136
Because of the way the loops are nested in this program, it is
time-consuming to execute. A better and faster method is shown in
the following program.
0010 PRINT
I
H
Q
D
0020 FOR H=O TO 2
0030 FOR Q=O TO 4-2*H
0040 FOR D=O TO 10-5*H-2,5*Q
0050 FOR N=O TO 20-10*H-5*Q-2*D
0060 P=100-50*H-25*Q-l0*D-5*N
o
0 "'l 0 C :::: C -{-- 1
0080 PRINT FLP,H;Q;D;N;P
0090 NEXT N
0:1.00
NEXT
D
0:1.10 NEXT
Q
0120
NEXT H
0130 PRINT FLP, 'TOTAL WAYS ='C
N
P'
o
(
""
.... ,,)1
136
Because of the way the loops are nested in this program, it is
time-consuming to execute. A better and faster method is shown in
the following program.
0010 PRINT
I
H
Q
D
0020 FOR H=O TO 2
0030 FOR Q=O TO 4-2*H
0040 FOR D=O TO 10-5*H-2,5*Q
0050 FOR N=O TO 20-10*H-5*Q-2*D
0060 P=100-50*H-25*Q-l0*D-5*N
o
0 "'l 0 C :::: C -{-- 1
0080 PRINT FLP,H;Q;D;N;P
0090 NEXT N
0:1.00
NEXT
D
0:1.10 NEXT
Q
0120
NEXT H
0130 PRINT FLP, 'TOTAL WAYS ='C
N
P'
o
(
""
.... ,,)1

Advertisement

Table of Contents
loading

Table of Contents