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 DATAN = N - 1,2,3,4,5: DIM A(N)
40 NFOR I = N - 1:0 DIMTO A(N)
50 READ FOR A(I): = 0 TO NNEXT
60 FOR READ A(I): NEXT= 0 TO N
70 S FOR= S + A(I):P = 0P TO* NA(I)
90 80 NEXT
80 S = S + A(I):P = P * A(I)
100 90 PRINT "SUM="S,"PRODUCT="P</lang>
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
8070 S = S + A(I):P = P * A(I)
80 NEXT I
90 PRINT "SUM=";S,"PRODUCT=";P</lang>
 
==={{header|BaCon}}===
1,480

edits