Paper VII GROUP A: Unit I
Dear MSc Second Year Zoology (V.U) StudentsSo far we have seen that we can store a single value in a variable for example:
10 Let A = 10
But while programming it may be convenient to store a list of values (i.e. 10,5,15,20,25) in a single variable. This is possible in BASIC and such a list in called "array", each individual item is called an "element". So "A" is an array and its elements are A1= 10, A2 = 5, A3=15, A4= 20, A5=25. 1 in "A1" denotes position of the element in an array and is called its "index" or "subscription".
To make an array in BASIC we use DIM statement, say if we want to make an array of 10 elements and save it in variable "N" then the statement wii be
10 DIM N(10) This will create an empty array of 10 elements. To fill this array we can take the elements as input or we can use READ and DATA statements.
DATA statement saves a list of elements.
READ statements reads the list one at a time and puts it in array
Example: Program to calculate sum of squares of 10 numbers.
-
10 Cls
- Write a program using array to calculate mean and variance of heights of dogs, heights are : 600 mm, 470 mm,170 mm, 430mm and 300 mm.
- Further Reading: A blog with many qbasic examples
- Open WikiBook
20 LET S = 0
30 FOR I = 1 to 10
40 READ X(I)
50 LET S = S + X(I)*X(I)
60 NEXT I
70 NEXT I
80 PRINT S
90 DATA 1,2,3,4,5,6,7,8,9,10
100 END
Your assignment:
If you face any problems or you want to discuss this assignment please feel free to leave a comment.
No comments:
Post a Comment