Private Sub Command1_Click()
'宣告二維陣列
Dim a(2, 2) As Integer, b(2, 2) As Integer, c(2, 2) As Integer
Call datainput(a(), b()) '呼叫資料輸入介面
Call process(a(), b(), c()) '呼叫處理資料介面
Call prn(c()) '呼叫輸出資料介面
End Sub
Public Sub datainput(a() As Integer, b() As Integer)
Dim i As Integer '宣告計數變數
Open Text1.Text For Input As #1 '開啟檔案
For i = 1 To 2 '讀取資料至 a 陣列
Input #1, a(i, 1), a(i, 2) '列運算讀取一列資料
Next
For i = 1 To 2 '讀取資料至 b 陣列
Input #1, b(i, 1), b(i, 2) '列運算讀取一列資料
Next
Close '關閉檔案
End Sub
Public Sub process(a() As Integer, b() As Integer, c() As Integer)
Dim i As Integer '宣告計數變數
For i = 1 To 2 '控制列運算
c(i, 1) = a(i, 1) + b(i, 1) '第 1 行的運算
c(i, 2) = a(i, 2) + b(i, 2) '第 2 行的運算
Next
End Sub
Sub prn(c() As Integer)
Dim i As Integer
'Printer.FontSize = 20 '設定列表機輸出字型大小 (可省略)
'Printer.Print "第五題結果:"
For i = 1 To 2 '每一列的結果輸出
List1.AddItem ("[" & c(i, 1) & " " & c(i, 2) & "]")
'Printer.Print "["; c(i, 1); " "; c(i, 2); "]"
Next
'Printer.EndDoc '結束列印
End Sub
2008年4月19日 星期六
矩陣相加
基本架構練習:
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言