字體:小 中 大 | |
|
|
2010/02/22 19:25:03瀏覽1794|回應0|推薦1 | |
第5題解題程式 FOR迴圈版 Private Sub cmd_no5_Click() '************************** '*119-940305 Program Start* '************************** Open "A:\940305.SM" For Input As #1 Dim a(2, 2), b(2, 2), S(2, 2) Input #1, a(1, 1), a(1, 2), a(2, 1), a(2, 2) '讀取檔案 Input #1, b(1, 1), b(1, 2), b(2, 1), b(2, 2) Close #1 For i = 1 To 2 For j = 1 To 2 S(i, j) = a(i, j) + b(i, j) '矩陣相加s(1,1)=a(1,1)+(b(1,1) Next T = T & "[" & S(i, 1) & " " & S(i, 2) & "]" & vbCrLf Next Txt_no5.Text = "第五題結果:" & vbCrLf & T End Sub DO WHILE迴圈 前測版 Private Sub cmd_no5_Click() '************************** '*119-940305 Program Start* '************************** Open "A:\940305.SM" For Input As #1 Dim a(2, 2), b(2, 2), S(2, 2) Input #1, a(1, 1), a(1, 2), a(2, 1), a(2, 2) Input #1, b(j, 1), b(j, 2), b(2, 1), b(2, 2) i = 1 Do While i <= 2 j = 1 Do While j <= 2 S(i, j) = a(i, j) + b(i, j) j = j + 1 Loop T = T & "[" & S(i, 1) & " " & S(i, 2) & "]" & vbCrLf i = i + 1 Loop Txt_no5.Text = "第五題結果:" & vbCrLf & T End Sub DO WHILE 迴圈後測版 Private Sub Cmd_no5_Click() '************************** '*119-940305 Program Start* '************************** Open "A:\940305.SM" For Input As #1 Dim a(2, 2), b(2, 2), S(2, 2) Input #1, a(1, 1), a(1, 2), a(2, 1), a(2, 2) Input #1, b(j, 1), b(j, 2), b(2, 1), b(2, 2) i = 1 Do j = 1 Do S(i, j) = a(i, j) + b(i, j) j = j + 1 Loop While j <= 2 T = T & "[" & S(i, 1) & " " & S(i, 2) & "]" & vbCrLf i = i + 1 Loop While i <= 2 txt_no5.Text = "第四題結果:" & vbCrLf & T End Sub 執行畫面 |
|
( 休閒生活|網路生活 ) |