Вы находитесь на странице: 1из 7

CHAPTER No.

ARRAYS

CLASS 10TH

ARRAYS
Chapter No. 4 English Medium

Class 10th
Zeeshan
Visit: www.zeeshanfaizali.blogspot.com
Notes Prepared By Zeeshan Faiz
Visit:www.zeeshanfaizali.blogspot.com

1|Page

CHAPTER No. 4

ARRAYS

CLASS 10TH

Short Questions
1) Why we need an array?
If we have to use hundred and thousands of different variables in a program, it will become
difficult to handle them. For example to store names of hundred students in a computer. It needs
hundred different variable names. So an array can solve this problem by defining the same type
of variable under the same name with different reference number.
2) Define an array.
An array is a collection of variables that can store data of same type. Each memory location
holds a single value which is called an element of an array. The general syntax of array is:
Array name (size of array)
For example: A(4) and B$(5).
3) What is element of the array?
The array is represented in the computers memory by a set of consecutive memory locations.
These memory locations are referred to as elements of the array.
4) What is index or subscript?
Each array is given a name and the elements of the array are accessed with reference to their
position or location number. This position number is called index or subscript. The subscript or
index value is written in parenthesis with the name of array.
5) Why array is called subscript variable?
An array is called a subscript variable because when we need to access a certain element; we
must use a subscript to point to that element so we can differentiate it from the rest. All array
elements in an array have the same variable name, which is also the name of the entire array.
6) How values can be assigned to array?
Values can be assigned to the subscripted variable or array by LET statement, READ . DATA
statement or INPUT statement. The size of subscript / index value can be a variable or number or
a numeric expression.
7) Write a program to describe the filling and printing of an array using READ DATA.
5 N$(4)
10 FOR K=1 TO 4
20 READ N$(K)
30 PRINT N$(K)
40 NEXT K
50 DATA Ali, Hamza, Ahsan, Moiz
60 END
8) Write a program to describe the filling and printing of an array using INPUT statement.
5 N$(4)
10 FOR K=1 TO 4
20 INPUT Enter the name of student= , N$(K)
30 NEXT K
40 FOR K=1 TO 4
50 PRINT N$(K)
60 NEXT K
70 END
9) Write syntax and purpose of DIM statement.
By default GWBASIC provides an array for storing 10 elements, from subscript 0 to 9. If we
need to store more than 10 values in an array we use DIM statement with that array. DIM stands
for DIMENSION.
Syntax: Line No. DIM subscripted variable1, subscripted variable2,

Notes Prepared By Zeeshan Faiz


Visit:www.zeeshanfaizali.blogspot.com

2|Page

CHAPTER No. 4

ARRAYS

CLASS 10TH

10) What is the use of DIM?


DIM is used to create memory variable. It specifies the maximum value for an array variable
subscript and allocates storage accordingly. By using DIM we can store up to 256 elements in an
array.
11) What information must be considered before applying subscript variable?
When subscript variables are used in a program, certain information must be considered before
applying.
a) Name of subscript.
b) Size of subscript.
c) We can define more than one array variable in one DIM statement.
d) Subscript variable may be string or numeric.
12) Write a program to find the largest number from the list.
10 DIM NUM(100)
20 INPUT How many numbers you want to enter; max: 100= ,LIMIT
30 FOR K=1 TO LIMIT
40 INPUT Enter any Number= ,NUM(K)
50 NEXT K
60 LARGE = NUM (1)
70 FOR M=1 TO LIMIT
80 IF LARGE < NUM(M) THEN LARGE = NUM(M)
90 NEXT M
100 PRINT Large number of list is= ;LARGE
110 END
13) Name categories of array.
Array can be divided into two major categories.
a) One-dimensional array
b) Two-dimensional array
14) What is one-dimensional array? Write its syntax.
One-dimensional array is also known as linear array or vector array. It consists of only one row
or column. It is also called 1-D array.
Syntax:
Line No.
DIM array name /variable (size of array)
15) Write a program to describe the use of one-dimensional array.
5
SUM = 0
10
FOR K=1 TO 5
20
READ MARK (K)
30
SUM = SUM + MARK (K)
40
NEXT K
50
AVG = SUM/5
60
FOR M=1 TO 5
70
PRINT MARK (M)
80
NEXT M
90
PRINT Sum of marks of a class in a subject= ;SUM
100
PRINT Average of marks= ;AVG
110
DATA 88,66,49,55,78
120
END

Notes Prepared By Zeeshan Faiz


Visit:www.zeeshanfaizali.blogspot.com

3|Page

CHAPTER No. 4

ARRAYS

CLASS 10TH

16) Define 2-D Array and write its syntax.


The two dimension array consists of rows and columns. It is also known as table or matrix. Two
Dimensional array is also defined as: array of one-dimensional arrays.
Syntax:
Line No. DIM array variable (row, col)
Where array variable represents the name of two-dimensional array. rows represents the total
number of rows of table. col represents the total number of columns of the table.
17) How Data is entered into two-dimensional array?
Data is entered into individual elements of a two-dimensional array. To enter data, the element is
referenced by its index or subscript value. This is done by using the nested loop.
18) How data is retrieved from two-dimensional array?
Data is retrieved from individual elements of a two-dimensional array. To retrieve data, the
element is referenced by its index or subscripts value. This is done by using nested loop.
19) How nested loop is used to enter data into two-dimensional array?
Nested loop is used to enter data into the elements of the two-dimensional array. The outer loop
has been used to change the index values of rows and inner loop is used to change the index
values of columns.
20) How nested loop is used to print the elements of two-dimensional array?
Nested loop is used to print the elements of the two-dimensional array. The outer loop has been
used to change the index values of rows and inner loop is used to change the index values of
columns.
21) Write a program to show the filling and printing of two-dimensional array.
The following program inputs data into two array and then prints out the sum of array on the
computer screen in the tabular form.
10 DIM A(2,2), B(2,2), Z(2,2)
20 FOR R=1 TO 2
30 FOR C=1 TO 2
40 READ A(R,C) , B(R,C)
50 Z(R,C) = A(R,C) + B(R,C)
60 PRINT Z(R,C),
70 NEXT C
80 PRINT
90 NEXT R
100 DATA 8,4,3,5
110 DATA 6,4,5,5
120 END
22) What is array manipulation?
The array manipulation is define as an operation that can be performed by using array, like
searching a particular element in an array, matching elements from two different arrays, sorting
array, finding largest and smallest number from an array and rearranging the array.
EXERCISE
4. What is meant by DIM statement?
Answer from question No. 9 and 10.
5. Describe the use of subscript variable in array.

Notes Prepared By Zeeshan Faiz


Visit:www.zeeshanfaizali.blogspot.com

4|Page

CHAPTER No. 4

ARRAYS

CLASS 10TH

A subscript in an array is used to locate or access the elements of the array that are already stored
in it. Or it is also used to locate that position where element will be stored.
6. How would you Fill and Print the array?
Answer from question No. 8.
7. What is meant by array manipulation?
Answer from question No. 22.
8. Differentiate between 1-D array and 2-D array.
1-D Array
2-D Array
1. One dimensional array is like list where there
can only be one row or column.
2. This type of array needs only one loop to fill
and print its elements.
3. Only one subscript is requires to represents the
elements of the array.
4. Require DIM keyword if more than 10
elements need to be stored.
5. Syntax:
Line No. [DIM] arrayname(size of array)
6. E.g.
N(10), DIM A(20)

1. Two-dimensional array is like a table or


matrix. It contains both rows and columns.
2. This type of array needs nested loop to fill
and print its elements.
3. Two subscripts are used to represents the
elements of the array.
4. DIM keyword is used even if total elements
to be stored are less than 10.
5. Syntax:
Line No. DIM arrayname(row, col)
6. E.g.
DIM A(3,4), DIM B(10, 20)

9. Describe about the printing two-dimensional array with the help of an example.
Answer from question No. 18,19,20,21.
10. Write a program in BASIC to enter integer type data into an array and then to print the
values in the reverse order.
10
CLS
20
DIM N(10)
30
PRINT ENTER TEN VALUES
40
FOR K=1 TO 10
50
INPUT ENTER NUMBER= ,N(K)
60
NEXT K
70
PRINT NUMBERS IN REVERSE ORDER
80
FOR M=10 TO 1 STEP -1
90
PRINT N(M)
100
NEXT M
110
END
11. Differentiate between simple and subscript variable.
Simple variable
Subscript variable
1. It can store only one data element.
2. Every simple variable has a unique name that
distinguishes them from the rest.
3. It is also called variable.
4. Syntax:
Variablename = data element
5. E.g.
SUM = A + B, PRO = SUM * 4, A= 3

1. It can store multiple data elements depending


on its size
2. It has a same name for every data element
stored in it. And each element is distinguished
by its reference or position number.
3. It is also called array.
4. Syntax:
Line No. DIM arrayname(row, col)
Line No. [DIM] arrayname(size of array)
5. E.g.
A(3), DIM B(10, 20)

Notes Prepared By Zeeshan Faiz


Visit:www.zeeshanfaizali.blogspot.com

5|Page

CHAPTER No. 4

ARRAYS

CLASS 10TH

12. Draw a flowchart for the Q. No. 16 program.


Class work.
13. Write an algorithm to sum array A elements and array B elements.
STEP
ACTION
1
K=0
2
SUM=0
3
WHLIE ( ELEMENTS OF A OR ELEMENTS OF B)
4
READ A(K)
5
READ B(K)
6
SUM = A(K) + B(K)
7
K= K+1
8
WEND
9
PRINT SUM OF ARRAY A and B =
10
PRINT SUM
11
DATA ELEMENTS OF ARRAY A
12
DATA ELEMENTS OF ARRAY B
14. Write a program to print a list of odd numbers from the given numbers.
6, 42, 4, 77, 32, 9, 21, 22, 8, 45, 15, 46
10
CLS
20
DIM A(12)
30
FOR K=1 TO 12
40
READ A(K)
50
IF A(K) MOD 2 = 1 THEN PRINT A(K)
60
NEXT K
70
DATA 6, 42, 4, 77, 32, 9, 21, 22, 8, 45, 15, 46
80
END
15. Write a program that read an array N with 20 numbers and find the product of the
elements of array.
10
CLS
20
DIM N(20)
30
LET PRO = 1
40
PRINT ENTER 20 NUMBERS
50
FOR K=1 TO 20
60
INPUT ENTER NUMBER= ,N(K)
70
PRO = PRO * N(K)
80
NEXT K
90
PRINT PRODUCT OF GIVEN NUMBERS= ;PRO
100
END
16. Write a program that read Z having 12 numbers given by user then print the sum and
average of all array elements.
10
CLS
20
DIM Z(12)

Notes Prepared By Zeeshan Faiz


Visit:www.zeeshanfaizali.blogspot.com

6|Page

CHAPTER No. 4
30
40
50
60
70
80
90
100
110

ARRAYS

CLASS 10TH

LET SUM = 0
PRINT ENTER 12 NUMBERS
FOR K=1 TO 20
INPUT ENTER NUMBER= , Z(K)
SUM = SUM + Z(K)
NEXT K
PRINT SUM OF GIVEN NUMBERS= ;SUM
PRINT AVERAGE OF GIVEN NUMBERS= ;SUM/12
END

17. Find out errors in the following program segments if any.


a) 10
DIM N$(10)
b) 10
FOR J=K TO 15
20
FOR K=4 TO 15
20
K(J) = J
30
INPUT N$
30
PRINT K(J)
40
NEXT I
40
NEXT J
a)
Error on line number 20 change K=4 to 15 with K=1 to 10 and on line 30 change N$
with N$(K) and on line number 40 change I with K
b)
Error is because of lack of a line. Add DIM K(15) before line No. 10
18. Write a program to sort the list of 20 names in descending order.
10 CLS
20 DIM N$(20)
30 FOR C=1 TO 20
40 INPUT ENTER NAME= ,N$(C)
50 NEXT C
60 CLS
70 PRINT NAMES IN DESCENDING ORDER;
80 PRINT
90 FOR K=20 TO 1 STEP -1
100 PRINT N$(K) : PRINT;
110 NEXT K
120 END

Notes Prepared By Zeeshan Faiz


Visit:www.zeeshanfaizali.blogspot.com

7|Page

Вам также может понравиться