BASIC programs
This article is for analysis programming beginning.
10 REM DIMENSION AND AVERAGE
20 DIM A(4)
30 FOR I=0 TO 4
40 READ A(I)
50 NEXT I
60 DATA 0,1,2,3,4
70 REM AVERAGE
80 FOR M=0 TO 4
90 J=J+A(M)
100 NEXT M
110 PRINT M
120 PRINT M/5
130 END
We set DIM A(4), we READ data, we count all sum for DIM A(4), we print all sum for DIM A(4), we print average for DIM A(4).
If we do not clear dimension in memory, then dimension datas are in memory.
We can use this dimension datas in the same program.
Then,
We set DIM A(1, 4)
10 REM DIM A(I, J) AND ANALYSIS
20 DIM A(1,4)
30 FOR I=0 TO 1
40 FOR J=0 TO 4
50 READ (A(I,J)
60 PRINT "A(" ; I ; "," ; J ; ") ="; (A(I,J)
70 NEXT J
80 NEXT I
90 DATA 0,1,2,3,4
100 DATA 10,11,12,13,14
200 PRINT "A SAMPLE OF ANALYSIS"
210 FOR L=0 TO 4
220 S=S+A(0,L)
230 NEXT L
240 PRINT "TOTAL OF A(0,0,) A(0,1) A(0,2) A(0,3) A(0,4) ="; S
250 PRINT "AVERAGE OF A(0,0,) A(0,1) A(0,2) A(0,3) A(0,4) ="; S/5
300 END
This program shows many messages for you.
This program shows total and and average.
Can you make this program for A(1,0) A(1,1) A(1,2) A(1,3) A(1,4) ?
Can you make this program for all A(I,J) ?
Next program is;
10 REM INPUT AND AVERAGE
20 INPUT "COUNT ?" ; I
30 DIM A(I-1)
40 FOR J=0 TO (I-1)
50 INPUT A(J)
60 PRINT "A(" ; J ; ") =" ; A(J)
70 NEXT J
80 FOR L=0 TO (I-1)
90 S=S+A(L)
100 NEXT L
110 PRINT "INPUT NUMBERS COUNT =" ; I
120 PRINT "AVERAGE =" ; S/I
130 END
Let us run this program.
COUNT ?
then
2
First
?
then
155
Next
?
then
167.5
AVERAGE = 161.25
Please try by your family.
Next is CHAR$
10 REM CHAR$
20 INPUT CHAR$(A)
30 PRINT CHR$(A)
40 END
Then run this program,
?
You can input HELLO.
Computer will show HELLO.
10 REM CHAR$ AND GOTO
20 INPUT CHAR$(A)
30 PRINT CHAR$(A)
40 GOTO 20
50 END
You can talk with computer ?
Push Control key + C key at the same time will stop this program.
We used GOTO statement in this program.
GOTO 20 means GOTO Line number 20.
Homework: Make flow charts for all programs in this article.
(R.S.F. toshiki speed news press, Agence France-Presse, 11 Wednesday June 2014 The Roman)