puzzles/maximum-profit/MAXPROFIT.BAS

18 lines
385 B
QBasic
Raw Normal View History

2024-04-02 21:01:09 +00:00
10 DIM PRICES(6)
20 FOR I = 1 TO 6
30 READ PRICES(I)
40 NEXT I
50 LET BUY = PRICES(1)
60 LET MAXP = PRICES(2) - BUY
100 FOR I = 1 TO 6
110 IF (PRICES(I) - BUY) < MAXP THEN 130
120 LET MAXP = PRICES(I) - BUY
130 IF PRICES(I) > BUY THEN 150
140 BUY = PRICES(I)
150 NEXT I
200 IF MAXP < 0 THEN MAXP = 0
210 PRINT MAXP
300 END
1000 REM DEFINE STOCK PRICES BELOW
1010 DATA 7, 1, 5, 3, 6, 4