【電腦軟體設計】電腦軟體設計-丙級-術科測驗1站-第5題 - 東哥的G3之戀 - udn部落格
東哥的G3之戀
作家:東哥(沉浸在幸福裡!)
文章分類
    Top
    【電腦軟體設計】電腦軟體設計-丙級-術科測驗1站-第5題
    2010/02/22 19:25:03
    瀏覽:1809
    迴響:0
    推薦:1
    引用0

    第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

    執行畫面


    回應
    發表迴響

    會員登入