Fibonacci sequence: Difference between revisions
Content deleted Content added
→{{header|Commodore BASIC}}: Add support for negative indexes and showing a range instead of just single item. |
m →{{header|Commodore BASIC}}: Formatting |
||
Line 1,431:
<lang basic>100 PRINT CHR$(147); CHR$(18); "**** FIBONACCI GENERATOR ****"
110 INPUT "MIN, MAX"; N1, N2
120 IF N1 > N2 THEN T = N1: N1 = N2: N2 = T
130 A = 0: B = 1: S = SGN(N1)
140 FOR I = S TO N1 STEP S
150 : IF S > 0 THEN T = A + B: A = B: B = T
160 : IF S < 0 THEN T = B - A: B = A: A = T
170 NEXT I
180 PRINT
190 PRINT STR$(A); : REM STR$() PREVENTS TRAILING SPACE
200 IF N2 = N1 THEN 250
210 FOR I = N1 + 1 TO N2
220 : T = A + B: A = B: B = T
230 : PRINT ","; STR$(A);
240 NEXT I
250 PRINT</lang>
|