Sum and product of an array: Difference between revisions
→{{header|Atari BASIC}}: Add implementation.
(→{{header|Applesoft BASIC}}: Make code work for Commodore as well as Apple.) |
(→{{header|Atari BASIC}}: Add implementation.) |
||
Line 472:
{{works with|Commodore BASIC}}
<lang ApplesoftBasic> 10 N = 5
20 S = 0:P = 1: DATA 1,2,3,4,5
30
40
50 READ
60 FOR
70 S
80 S = S + A(I):P = P * A(I)▼
▲ 90 NEXT
▲ 100 PRINT "SUM="S,"PRODUCT="P</lang>
==={{header|Atari BASIC}}===
Almost the same code works in Atari BASIC, but you can't READ directly into arrays, leave the variable off a NEXT, or concatenate values in PRINT without semicolons between them:
<lang basic>10 N = 5
20 S = 0:P = 1: DATA 1,2,3,4,5
30 N = N - 1: DIM A(N)
40 FOR I = 0 TO N
50 READ X:A(I) = X: NEXT I
60 FOR I = 0 TO N
80 NEXT I
90 PRINT "SUM=";S,"PRODUCT=";P</lang>
==={{header|BaCon}}===
|