網路城邦
上一篇 回創作列表 下一篇   字體:
【電腦軟體設計】電腦軟體設計-丙級-術科測驗1站-第5題
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

執行畫面


( 休閒生活網路生活 )
回應 推薦文章 列印 加入我的文摘
上一篇 回創作列表 下一篇

引用
引用網址:https://classic-blog.udn.com/article/trackback.jsp?uid=zdzo&aid=2740058