Lecture (12)Multidimensional Arrays
-
Upload
safuanalcatra -
Category
Documents
-
view
235 -
download
0
Transcript of Lecture (12)Multidimensional Arrays
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 114
1
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Lecture 13
Multidimensional Arrays
Mdm Ratnawati Ibrahim
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 214
FSB23103 2
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Multidimensional arrays
- These are often used to represent tables of values arranged
in rows and columnsbull To identify a particular table element two indexes must
be specified The first identifies the elementrsquos row and thesecond its columnEg an array may be declared
Dim grid(3 2) As Integer This is a 4 row x 3 column table called grid whoseelements are of type integer
bull The largest index value of an array can be found usingUbound
(the smallest index value using LBound)Eg Dim info(19 27) As Integer largestRowIndex AsInteger
largestRowIndex = Ubound(info 1)produces the value 19
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 314
FSB23103 3
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Multidimensional arrays ndash contrsquod
bull As in the case of one dimension arrays initialisation may
be performed when the array is declaredEg Dim table( ) As Integer = 1 0 10 1 0
ie values are entered as rows
or by assignment statements later
bull Once created an array has a fixed size that can only bechanged explicitly using the ReDim command Even then only the last dimension can be modified Theoptional word Preserve causes the values of the array tobe preserved when the size is changed
Eg ReDim Preserve info(19 37)
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 414
FSB23103 4
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash Magic Squares
Re wwwmarkfarrarcoukmsfmsq01htm
bull A numeric magic square must consist of a series of numbersarranged in a square in such a manner that the each row eachcolumn and both the corner diagonals sum to the same amountwhich is called the magic total
bull The magic total may be determined from the formula
where n is the number of cells on each side of the magic square
The aim of the program is to display magic squares for oddvalues of n from 3 to 9 (Even number magic squares are morechallenging)
)1(2
2+times n
n
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 514
FSB23103 5
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod
Analysis
1 What is to be input n the number of cells on eachside of the square
2 How is problem to be solved ndash Construct analgorithm
(i) Place 1 in middle cell of top row
(ii) Move diagonally up to next cell (rows and columnswrap around - above top row becomes bottomrow outside right most column becomes leftmostcolumn)
(iii)If cell occupied move to cell directly belowotherwise enter next number
(iv)If not last number ( ) go back to step (ii)
3 What is to be output Grid of numbers and magictotal
2n
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 614
FSB23103 6
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod
Form designMagic Squares
Enter odd n lt 10 Find
Exit
Label lblTitle
Label lblPrompt Button cmdFind
Button cmdExit
PictureBox
picBox
Textbox
txtNumber
Magic total is
Label
lblMagicTotal
Run
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 714
FSB23103 7
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod
Algorithm design findOddSolution (grid( )n)
Start
i = 0
j =(n-1) 2
k = 1
k gt nn
grid(i j) = k
nextI = i ndash 1nextJ = j + 1
1 End
Yes
No
3
n ndash side of squarei ndash row position
j ndash column position
Set initial position
Top row centre
k - number to be placed in grid
Is number greater than max
possible
Store number
Determine next position
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 814
FSB23103 8
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod
Algorithm design - contrsquod
1
nextI lt 0
nextJ gt n - 1
nextI = n - 1
nextJ = 0
2
Yes
Yes
No
No
Is next position above top line
Move to bottom row
Is next position to right of
last column
Move to first (leftmost) column
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 914
FSB23103 9
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod Algorithm design - contrsquod 2
grid(nextInextJ) gt 0
nextI gt n - 1
nextI = 0
i = nextI
j = nextJ
k = k +1
nextI = i + 1
nextJ = j
No
No
Yes
Yes
3
Is cell occupied
Move down one cell
Is next position below
bottom row
Move to top row
Confirm next position
Increase number by 1
grid(nextInextJ) gt 0
nextI gt n - 1
nextI = 0
i = nextI
j = nextJ
k = k +1
nextI = i + 1
nextJ = j
No
No
Yes
Yes
Is cell occupied
Move down one cell
Is next position below
bottom row
Move to top row
Confirm next position
Increase number by 1
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1014 FSB23103 10
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Method Implementation
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1114 FSB23103 11
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Input design
Need to 1 ensure entries of storage array grid are set to 0
2 clear display picture box
3 receive dimension of square performing any validationchecks
Output design
Once arrangement of numbers has been determined andstored in grid array we require code to format and outputsolution
Suggest this might be a chequered board with numberscontrasting with the colour of their cell Accordingly werequire lsquoSquarersquo object and routine to output black and whitesquares with appropriate numbers
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1214 FSB23103 12
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Function implementation magicNumber(n)
Form1 code
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1314 FSB23103 13
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Form1 code - contrsquod
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1414FSB23103 14
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Form1 code - contrsquod
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 214
FSB23103 2
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Multidimensional arrays
- These are often used to represent tables of values arranged
in rows and columnsbull To identify a particular table element two indexes must
be specified The first identifies the elementrsquos row and thesecond its columnEg an array may be declared
Dim grid(3 2) As Integer This is a 4 row x 3 column table called grid whoseelements are of type integer
bull The largest index value of an array can be found usingUbound
(the smallest index value using LBound)Eg Dim info(19 27) As Integer largestRowIndex AsInteger
largestRowIndex = Ubound(info 1)produces the value 19
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 314
FSB23103 3
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Multidimensional arrays ndash contrsquod
bull As in the case of one dimension arrays initialisation may
be performed when the array is declaredEg Dim table( ) As Integer = 1 0 10 1 0
ie values are entered as rows
or by assignment statements later
bull Once created an array has a fixed size that can only bechanged explicitly using the ReDim command Even then only the last dimension can be modified Theoptional word Preserve causes the values of the array tobe preserved when the size is changed
Eg ReDim Preserve info(19 37)
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 414
FSB23103 4
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash Magic Squares
Re wwwmarkfarrarcoukmsfmsq01htm
bull A numeric magic square must consist of a series of numbersarranged in a square in such a manner that the each row eachcolumn and both the corner diagonals sum to the same amountwhich is called the magic total
bull The magic total may be determined from the formula
where n is the number of cells on each side of the magic square
The aim of the program is to display magic squares for oddvalues of n from 3 to 9 (Even number magic squares are morechallenging)
)1(2
2+times n
n
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 514
FSB23103 5
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod
Analysis
1 What is to be input n the number of cells on eachside of the square
2 How is problem to be solved ndash Construct analgorithm
(i) Place 1 in middle cell of top row
(ii) Move diagonally up to next cell (rows and columnswrap around - above top row becomes bottomrow outside right most column becomes leftmostcolumn)
(iii)If cell occupied move to cell directly belowotherwise enter next number
(iv)If not last number ( ) go back to step (ii)
3 What is to be output Grid of numbers and magictotal
2n
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 614
FSB23103 6
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod
Form designMagic Squares
Enter odd n lt 10 Find
Exit
Label lblTitle
Label lblPrompt Button cmdFind
Button cmdExit
PictureBox
picBox
Textbox
txtNumber
Magic total is
Label
lblMagicTotal
Run
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 714
FSB23103 7
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod
Algorithm design findOddSolution (grid( )n)
Start
i = 0
j =(n-1) 2
k = 1
k gt nn
grid(i j) = k
nextI = i ndash 1nextJ = j + 1
1 End
Yes
No
3
n ndash side of squarei ndash row position
j ndash column position
Set initial position
Top row centre
k - number to be placed in grid
Is number greater than max
possible
Store number
Determine next position
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 814
FSB23103 8
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod
Algorithm design - contrsquod
1
nextI lt 0
nextJ gt n - 1
nextI = n - 1
nextJ = 0
2
Yes
Yes
No
No
Is next position above top line
Move to bottom row
Is next position to right of
last column
Move to first (leftmost) column
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 914
FSB23103 9
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod Algorithm design - contrsquod 2
grid(nextInextJ) gt 0
nextI gt n - 1
nextI = 0
i = nextI
j = nextJ
k = k +1
nextI = i + 1
nextJ = j
No
No
Yes
Yes
3
Is cell occupied
Move down one cell
Is next position below
bottom row
Move to top row
Confirm next position
Increase number by 1
grid(nextInextJ) gt 0
nextI gt n - 1
nextI = 0
i = nextI
j = nextJ
k = k +1
nextI = i + 1
nextJ = j
No
No
Yes
Yes
Is cell occupied
Move down one cell
Is next position below
bottom row
Move to top row
Confirm next position
Increase number by 1
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1014 FSB23103 10
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Method Implementation
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1114 FSB23103 11
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Input design
Need to 1 ensure entries of storage array grid are set to 0
2 clear display picture box
3 receive dimension of square performing any validationchecks
Output design
Once arrangement of numbers has been determined andstored in grid array we require code to format and outputsolution
Suggest this might be a chequered board with numberscontrasting with the colour of their cell Accordingly werequire lsquoSquarersquo object and routine to output black and whitesquares with appropriate numbers
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1214 FSB23103 12
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Function implementation magicNumber(n)
Form1 code
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1314 FSB23103 13
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Form1 code - contrsquod
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1414FSB23103 14
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Form1 code - contrsquod
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 314
FSB23103 3
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Multidimensional arrays ndash contrsquod
bull As in the case of one dimension arrays initialisation may
be performed when the array is declaredEg Dim table( ) As Integer = 1 0 10 1 0
ie values are entered as rows
or by assignment statements later
bull Once created an array has a fixed size that can only bechanged explicitly using the ReDim command Even then only the last dimension can be modified Theoptional word Preserve causes the values of the array tobe preserved when the size is changed
Eg ReDim Preserve info(19 37)
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 414
FSB23103 4
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash Magic Squares
Re wwwmarkfarrarcoukmsfmsq01htm
bull A numeric magic square must consist of a series of numbersarranged in a square in such a manner that the each row eachcolumn and both the corner diagonals sum to the same amountwhich is called the magic total
bull The magic total may be determined from the formula
where n is the number of cells on each side of the magic square
The aim of the program is to display magic squares for oddvalues of n from 3 to 9 (Even number magic squares are morechallenging)
)1(2
2+times n
n
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 514
FSB23103 5
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod
Analysis
1 What is to be input n the number of cells on eachside of the square
2 How is problem to be solved ndash Construct analgorithm
(i) Place 1 in middle cell of top row
(ii) Move diagonally up to next cell (rows and columnswrap around - above top row becomes bottomrow outside right most column becomes leftmostcolumn)
(iii)If cell occupied move to cell directly belowotherwise enter next number
(iv)If not last number ( ) go back to step (ii)
3 What is to be output Grid of numbers and magictotal
2n
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 614
FSB23103 6
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod
Form designMagic Squares
Enter odd n lt 10 Find
Exit
Label lblTitle
Label lblPrompt Button cmdFind
Button cmdExit
PictureBox
picBox
Textbox
txtNumber
Magic total is
Label
lblMagicTotal
Run
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 714
FSB23103 7
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod
Algorithm design findOddSolution (grid( )n)
Start
i = 0
j =(n-1) 2
k = 1
k gt nn
grid(i j) = k
nextI = i ndash 1nextJ = j + 1
1 End
Yes
No
3
n ndash side of squarei ndash row position
j ndash column position
Set initial position
Top row centre
k - number to be placed in grid
Is number greater than max
possible
Store number
Determine next position
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 814
FSB23103 8
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod
Algorithm design - contrsquod
1
nextI lt 0
nextJ gt n - 1
nextI = n - 1
nextJ = 0
2
Yes
Yes
No
No
Is next position above top line
Move to bottom row
Is next position to right of
last column
Move to first (leftmost) column
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 914
FSB23103 9
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod Algorithm design - contrsquod 2
grid(nextInextJ) gt 0
nextI gt n - 1
nextI = 0
i = nextI
j = nextJ
k = k +1
nextI = i + 1
nextJ = j
No
No
Yes
Yes
3
Is cell occupied
Move down one cell
Is next position below
bottom row
Move to top row
Confirm next position
Increase number by 1
grid(nextInextJ) gt 0
nextI gt n - 1
nextI = 0
i = nextI
j = nextJ
k = k +1
nextI = i + 1
nextJ = j
No
No
Yes
Yes
Is cell occupied
Move down one cell
Is next position below
bottom row
Move to top row
Confirm next position
Increase number by 1
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1014 FSB23103 10
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Method Implementation
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1114 FSB23103 11
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Input design
Need to 1 ensure entries of storage array grid are set to 0
2 clear display picture box
3 receive dimension of square performing any validationchecks
Output design
Once arrangement of numbers has been determined andstored in grid array we require code to format and outputsolution
Suggest this might be a chequered board with numberscontrasting with the colour of their cell Accordingly werequire lsquoSquarersquo object and routine to output black and whitesquares with appropriate numbers
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1214 FSB23103 12
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Function implementation magicNumber(n)
Form1 code
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1314 FSB23103 13
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Form1 code - contrsquod
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1414FSB23103 14
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Form1 code - contrsquod
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 414
FSB23103 4
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash Magic Squares
Re wwwmarkfarrarcoukmsfmsq01htm
bull A numeric magic square must consist of a series of numbersarranged in a square in such a manner that the each row eachcolumn and both the corner diagonals sum to the same amountwhich is called the magic total
bull The magic total may be determined from the formula
where n is the number of cells on each side of the magic square
The aim of the program is to display magic squares for oddvalues of n from 3 to 9 (Even number magic squares are morechallenging)
)1(2
2+times n
n
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 514
FSB23103 5
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod
Analysis
1 What is to be input n the number of cells on eachside of the square
2 How is problem to be solved ndash Construct analgorithm
(i) Place 1 in middle cell of top row
(ii) Move diagonally up to next cell (rows and columnswrap around - above top row becomes bottomrow outside right most column becomes leftmostcolumn)
(iii)If cell occupied move to cell directly belowotherwise enter next number
(iv)If not last number ( ) go back to step (ii)
3 What is to be output Grid of numbers and magictotal
2n
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 614
FSB23103 6
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod
Form designMagic Squares
Enter odd n lt 10 Find
Exit
Label lblTitle
Label lblPrompt Button cmdFind
Button cmdExit
PictureBox
picBox
Textbox
txtNumber
Magic total is
Label
lblMagicTotal
Run
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 714
FSB23103 7
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod
Algorithm design findOddSolution (grid( )n)
Start
i = 0
j =(n-1) 2
k = 1
k gt nn
grid(i j) = k
nextI = i ndash 1nextJ = j + 1
1 End
Yes
No
3
n ndash side of squarei ndash row position
j ndash column position
Set initial position
Top row centre
k - number to be placed in grid
Is number greater than max
possible
Store number
Determine next position
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 814
FSB23103 8
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod
Algorithm design - contrsquod
1
nextI lt 0
nextJ gt n - 1
nextI = n - 1
nextJ = 0
2
Yes
Yes
No
No
Is next position above top line
Move to bottom row
Is next position to right of
last column
Move to first (leftmost) column
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 914
FSB23103 9
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod Algorithm design - contrsquod 2
grid(nextInextJ) gt 0
nextI gt n - 1
nextI = 0
i = nextI
j = nextJ
k = k +1
nextI = i + 1
nextJ = j
No
No
Yes
Yes
3
Is cell occupied
Move down one cell
Is next position below
bottom row
Move to top row
Confirm next position
Increase number by 1
grid(nextInextJ) gt 0
nextI gt n - 1
nextI = 0
i = nextI
j = nextJ
k = k +1
nextI = i + 1
nextJ = j
No
No
Yes
Yes
Is cell occupied
Move down one cell
Is next position below
bottom row
Move to top row
Confirm next position
Increase number by 1
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1014 FSB23103 10
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Method Implementation
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1114 FSB23103 11
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Input design
Need to 1 ensure entries of storage array grid are set to 0
2 clear display picture box
3 receive dimension of square performing any validationchecks
Output design
Once arrangement of numbers has been determined andstored in grid array we require code to format and outputsolution
Suggest this might be a chequered board with numberscontrasting with the colour of their cell Accordingly werequire lsquoSquarersquo object and routine to output black and whitesquares with appropriate numbers
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1214 FSB23103 12
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Function implementation magicNumber(n)
Form1 code
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1314 FSB23103 13
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Form1 code - contrsquod
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1414FSB23103 14
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Form1 code - contrsquod
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 514
FSB23103 5
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod
Analysis
1 What is to be input n the number of cells on eachside of the square
2 How is problem to be solved ndash Construct analgorithm
(i) Place 1 in middle cell of top row
(ii) Move diagonally up to next cell (rows and columnswrap around - above top row becomes bottomrow outside right most column becomes leftmostcolumn)
(iii)If cell occupied move to cell directly belowotherwise enter next number
(iv)If not last number ( ) go back to step (ii)
3 What is to be output Grid of numbers and magictotal
2n
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 614
FSB23103 6
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod
Form designMagic Squares
Enter odd n lt 10 Find
Exit
Label lblTitle
Label lblPrompt Button cmdFind
Button cmdExit
PictureBox
picBox
Textbox
txtNumber
Magic total is
Label
lblMagicTotal
Run
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 714
FSB23103 7
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod
Algorithm design findOddSolution (grid( )n)
Start
i = 0
j =(n-1) 2
k = 1
k gt nn
grid(i j) = k
nextI = i ndash 1nextJ = j + 1
1 End
Yes
No
3
n ndash side of squarei ndash row position
j ndash column position
Set initial position
Top row centre
k - number to be placed in grid
Is number greater than max
possible
Store number
Determine next position
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 814
FSB23103 8
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod
Algorithm design - contrsquod
1
nextI lt 0
nextJ gt n - 1
nextI = n - 1
nextJ = 0
2
Yes
Yes
No
No
Is next position above top line
Move to bottom row
Is next position to right of
last column
Move to first (leftmost) column
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 914
FSB23103 9
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod Algorithm design - contrsquod 2
grid(nextInextJ) gt 0
nextI gt n - 1
nextI = 0
i = nextI
j = nextJ
k = k +1
nextI = i + 1
nextJ = j
No
No
Yes
Yes
3
Is cell occupied
Move down one cell
Is next position below
bottom row
Move to top row
Confirm next position
Increase number by 1
grid(nextInextJ) gt 0
nextI gt n - 1
nextI = 0
i = nextI
j = nextJ
k = k +1
nextI = i + 1
nextJ = j
No
No
Yes
Yes
Is cell occupied
Move down one cell
Is next position below
bottom row
Move to top row
Confirm next position
Increase number by 1
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1014 FSB23103 10
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Method Implementation
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1114 FSB23103 11
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Input design
Need to 1 ensure entries of storage array grid are set to 0
2 clear display picture box
3 receive dimension of square performing any validationchecks
Output design
Once arrangement of numbers has been determined andstored in grid array we require code to format and outputsolution
Suggest this might be a chequered board with numberscontrasting with the colour of their cell Accordingly werequire lsquoSquarersquo object and routine to output black and whitesquares with appropriate numbers
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1214 FSB23103 12
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Function implementation magicNumber(n)
Form1 code
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1314 FSB23103 13
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Form1 code - contrsquod
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1414FSB23103 14
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Form1 code - contrsquod
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 614
FSB23103 6
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod
Form designMagic Squares
Enter odd n lt 10 Find
Exit
Label lblTitle
Label lblPrompt Button cmdFind
Button cmdExit
PictureBox
picBox
Textbox
txtNumber
Magic total is
Label
lblMagicTotal
Run
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 714
FSB23103 7
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod
Algorithm design findOddSolution (grid( )n)
Start
i = 0
j =(n-1) 2
k = 1
k gt nn
grid(i j) = k
nextI = i ndash 1nextJ = j + 1
1 End
Yes
No
3
n ndash side of squarei ndash row position
j ndash column position
Set initial position
Top row centre
k - number to be placed in grid
Is number greater than max
possible
Store number
Determine next position
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 814
FSB23103 8
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod
Algorithm design - contrsquod
1
nextI lt 0
nextJ gt n - 1
nextI = n - 1
nextJ = 0
2
Yes
Yes
No
No
Is next position above top line
Move to bottom row
Is next position to right of
last column
Move to first (leftmost) column
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 914
FSB23103 9
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod Algorithm design - contrsquod 2
grid(nextInextJ) gt 0
nextI gt n - 1
nextI = 0
i = nextI
j = nextJ
k = k +1
nextI = i + 1
nextJ = j
No
No
Yes
Yes
3
Is cell occupied
Move down one cell
Is next position below
bottom row
Move to top row
Confirm next position
Increase number by 1
grid(nextInextJ) gt 0
nextI gt n - 1
nextI = 0
i = nextI
j = nextJ
k = k +1
nextI = i + 1
nextJ = j
No
No
Yes
Yes
Is cell occupied
Move down one cell
Is next position below
bottom row
Move to top row
Confirm next position
Increase number by 1
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1014 FSB23103 10
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Method Implementation
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1114 FSB23103 11
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Input design
Need to 1 ensure entries of storage array grid are set to 0
2 clear display picture box
3 receive dimension of square performing any validationchecks
Output design
Once arrangement of numbers has been determined andstored in grid array we require code to format and outputsolution
Suggest this might be a chequered board with numberscontrasting with the colour of their cell Accordingly werequire lsquoSquarersquo object and routine to output black and whitesquares with appropriate numbers
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1214 FSB23103 12
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Function implementation magicNumber(n)
Form1 code
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1314 FSB23103 13
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Form1 code - contrsquod
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1414FSB23103 14
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Form1 code - contrsquod
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 714
FSB23103 7
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod
Algorithm design findOddSolution (grid( )n)
Start
i = 0
j =(n-1) 2
k = 1
k gt nn
grid(i j) = k
nextI = i ndash 1nextJ = j + 1
1 End
Yes
No
3
n ndash side of squarei ndash row position
j ndash column position
Set initial position
Top row centre
k - number to be placed in grid
Is number greater than max
possible
Store number
Determine next position
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 814
FSB23103 8
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod
Algorithm design - contrsquod
1
nextI lt 0
nextJ gt n - 1
nextI = n - 1
nextJ = 0
2
Yes
Yes
No
No
Is next position above top line
Move to bottom row
Is next position to right of
last column
Move to first (leftmost) column
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 914
FSB23103 9
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod Algorithm design - contrsquod 2
grid(nextInextJ) gt 0
nextI gt n - 1
nextI = 0
i = nextI
j = nextJ
k = k +1
nextI = i + 1
nextJ = j
No
No
Yes
Yes
3
Is cell occupied
Move down one cell
Is next position below
bottom row
Move to top row
Confirm next position
Increase number by 1
grid(nextInextJ) gt 0
nextI gt n - 1
nextI = 0
i = nextI
j = nextJ
k = k +1
nextI = i + 1
nextJ = j
No
No
Yes
Yes
Is cell occupied
Move down one cell
Is next position below
bottom row
Move to top row
Confirm next position
Increase number by 1
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1014 FSB23103 10
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Method Implementation
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1114 FSB23103 11
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Input design
Need to 1 ensure entries of storage array grid are set to 0
2 clear display picture box
3 receive dimension of square performing any validationchecks
Output design
Once arrangement of numbers has been determined andstored in grid array we require code to format and outputsolution
Suggest this might be a chequered board with numberscontrasting with the colour of their cell Accordingly werequire lsquoSquarersquo object and routine to output black and whitesquares with appropriate numbers
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1214 FSB23103 12
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Function implementation magicNumber(n)
Form1 code
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1314 FSB23103 13
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Form1 code - contrsquod
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1414FSB23103 14
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Form1 code - contrsquod
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 814
FSB23103 8
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod
Algorithm design - contrsquod
1
nextI lt 0
nextJ gt n - 1
nextI = n - 1
nextJ = 0
2
Yes
Yes
No
No
Is next position above top line
Move to bottom row
Is next position to right of
last column
Move to first (leftmost) column
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 914
FSB23103 9
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod Algorithm design - contrsquod 2
grid(nextInextJ) gt 0
nextI gt n - 1
nextI = 0
i = nextI
j = nextJ
k = k +1
nextI = i + 1
nextJ = j
No
No
Yes
Yes
3
Is cell occupied
Move down one cell
Is next position below
bottom row
Move to top row
Confirm next position
Increase number by 1
grid(nextInextJ) gt 0
nextI gt n - 1
nextI = 0
i = nextI
j = nextJ
k = k +1
nextI = i + 1
nextJ = j
No
No
Yes
Yes
Is cell occupied
Move down one cell
Is next position below
bottom row
Move to top row
Confirm next position
Increase number by 1
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1014 FSB23103 10
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Method Implementation
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1114 FSB23103 11
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Input design
Need to 1 ensure entries of storage array grid are set to 0
2 clear display picture box
3 receive dimension of square performing any validationchecks
Output design
Once arrangement of numbers has been determined andstored in grid array we require code to format and outputsolution
Suggest this might be a chequered board with numberscontrasting with the colour of their cell Accordingly werequire lsquoSquarersquo object and routine to output black and whitesquares with appropriate numbers
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1214 FSB23103 12
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Function implementation magicNumber(n)
Form1 code
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1314 FSB23103 13
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Form1 code - contrsquod
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1414FSB23103 14
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Form1 code - contrsquod
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 914
FSB23103 9
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceI
nstit
ute
Example ndash contrsquod Algorithm design - contrsquod 2
grid(nextInextJ) gt 0
nextI gt n - 1
nextI = 0
i = nextI
j = nextJ
k = k +1
nextI = i + 1
nextJ = j
No
No
Yes
Yes
3
Is cell occupied
Move down one cell
Is next position below
bottom row
Move to top row
Confirm next position
Increase number by 1
grid(nextInextJ) gt 0
nextI gt n - 1
nextI = 0
i = nextI
j = nextJ
k = k +1
nextI = i + 1
nextJ = j
No
No
Yes
Yes
Is cell occupied
Move down one cell
Is next position below
bottom row
Move to top row
Confirm next position
Increase number by 1
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1014 FSB23103 10
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Method Implementation
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1114 FSB23103 11
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Input design
Need to 1 ensure entries of storage array grid are set to 0
2 clear display picture box
3 receive dimension of square performing any validationchecks
Output design
Once arrangement of numbers has been determined andstored in grid array we require code to format and outputsolution
Suggest this might be a chequered board with numberscontrasting with the colour of their cell Accordingly werequire lsquoSquarersquo object and routine to output black and whitesquares with appropriate numbers
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1214 FSB23103 12
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Function implementation magicNumber(n)
Form1 code
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1314 FSB23103 13
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Form1 code - contrsquod
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1414FSB23103 14
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Form1 code - contrsquod
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1014 FSB23103 10
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Method Implementation
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1114 FSB23103 11
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Input design
Need to 1 ensure entries of storage array grid are set to 0
2 clear display picture box
3 receive dimension of square performing any validationchecks
Output design
Once arrangement of numbers has been determined andstored in grid array we require code to format and outputsolution
Suggest this might be a chequered board with numberscontrasting with the colour of their cell Accordingly werequire lsquoSquarersquo object and routine to output black and whitesquares with appropriate numbers
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1214 FSB23103 12
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Function implementation magicNumber(n)
Form1 code
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1314 FSB23103 13
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Form1 code - contrsquod
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1414FSB23103 14
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Form1 code - contrsquod
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1114 FSB23103 11
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Input design
Need to 1 ensure entries of storage array grid are set to 0
2 clear display picture box
3 receive dimension of square performing any validationchecks
Output design
Once arrangement of numbers has been determined andstored in grid array we require code to format and outputsolution
Suggest this might be a chequered board with numberscontrasting with the colour of their cell Accordingly werequire lsquoSquarersquo object and routine to output black and whitesquares with appropriate numbers
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1214 FSB23103 12
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Function implementation magicNumber(n)
Form1 code
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1314 FSB23103 13
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Form1 code - contrsquod
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1414FSB23103 14
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Form1 code - contrsquod
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1214 FSB23103 12
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Function implementation magicNumber(n)
Form1 code
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1314 FSB23103 13
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Form1 code - contrsquod
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1414FSB23103 14
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Form1 code - contrsquod
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1314 FSB23103 13
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Form1 code - contrsquod
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1414FSB23103 14
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Form1 code - contrsquod
8142019 Lecture (12)Multidimensional Arrays
httpslidepdfcomreaderfulllecture-12multidimensional-arrays 1414FSB23103 14
U
NIVERS
ITIKUAL
A
LUMPUR
M
alaysi a
FranceInstit
ute
Example ndash contrsquod
Form1 code - contrsquod