0% found this document useful (0 votes)
7 views

CIVIL 3010 array examples

Uploaded by

JUBAYAD
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

CIVIL 3010 array examples

Uploaded by

JUBAYAD
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Arrays

Examples

1. Using one or more arrays, write a Visual Basic program to read in a 10 x 10 matrix from
cells(1,1) to cells(10,10) and then print out the matrix below it starting with cells(12,1).
2. Write a Visual Basic program to read in two 2 x 3 matrices [A] and [B], add them together,
and output the resulting matrix [C]=[A]+[B]. After execution, your spreadsheet should look
like:

48
3. Write a Visual Basic program to read in any m x n matrix [A] starting in cells(5,1) and then
output the transpose matrix [A]T below [A]. For example, for a 3 x 4 [A] matrix, after
execution your spreadsheet should look like:

For example, for a 8 x 2 [A] matrix, after execution your spreadsheet should look like:

49
The part of the code for reading in a generic m x n matrix, calculating m and n, and then re-
dimensioning the [A] and [A]T arrays is

Dim A() As Single, At() As Single


Dim i As Integer, j As Integer, m As Integer, n As Integer

Do While Cells(5 + m, 1) <> Empty


m=m+1
Loop

Do While Cells(5, n + 1) <> Empty


n=n+1
Loop

ReDim A(m, n) As Single, At(n, m) As Single

50
4. Write a Visual Basic program to read in a 3 x 3 matrix [A] and a 3 x 2 matrix [B], multiply
them together, and then output the resulting matrix [C] = [A] x [B]. After execution, your
spreadsheet should look like:

The part of the code for calculating each entry of the resulting [C] matrix is:

For k = 1 To 3

C(i, j) = C(i, j) + A(i, k) * B(k, j)

Next k

51

You might also like