Lec 10 Arrays
Lec 10 Arrays
Net
AAPP00-8-3-2
Arrays
Lecture 10
Topic & Structure of the lesson
•Introduction
•One Dimensional array
•Sorting an array
•Searching an array
•Multidimensional array
The table below gives names and test scores from a math
contest. Write a program to display the names of the students
scoring above the average for these eight students.
Richard 135
Geraldine 114
James 92
John 91
Paul 150
Max 114
Robert 91
Barbara 124
For j = 1 To 20
If num(j) Mod 2 = 0 Then
count(2) = count(2) + 1
End If
If num(j) Mod 3 = 0 Then
count(3) = count(3) + 1
End If
After Sorting
9876543210
Binary search
Eliminates searching through redundant
arrays by comparing the search key with
the middle element (array must be
sorted) Like searching through a
dictionary
0 1 2 3 4 5 6 7
0 If we were to represent
1 a chess board using a
multi-dimensional
2
array, we will have the
3 following declaration:
4
Dim chess(7,7) As Integer
5
6
Red square: chess(5,4)
7
Option explicit
‘store values into a two dimensional array
Dim n(2, 3) As Integer
Private Sub Command1_Click()
For i = 0 To 2
For j = 0 To 3
n(i, j) = CInt(InputBox(“Enter value for Row ” & i
& “Column ” & j))
Next
Next
‘display contents of the array to listbox
For i = 0 To 2
For j = 0 To 3
List1.AddItem n(i, j)
Next
Next
End Sub
Files