VB程序设计,求一个3行3列矩阵的3行中的元素之和最大的那一行.

1个回答

  • Dim i As Integer, j As Integer, a(1 To 3, 1 To 3) As Integer, b(1 To 3) As Integer, max As Integer, maxi As Integer

    Private Sub Command1_Click()

    For i = 1 To 3

    For j = 1 To 3

    Randomize

    a(i, j) = Int((100 - 1 + 1) * Rnd + 1)

    Print Format(a(i, j), "@@@@@");

    Next

    Print

    Next

    Print

    End Sub

    Private Sub Command2_Click()

    For i = 1 To 3

    For j = 1 To 3

    b(i) = b(i) + a(i, j)

    Next

    Next

    maxi = 1

    max = b(1)

    For i = 2 To 3

    If b(i) >= max Then max = b(i): maxi = i

    Next

    Print "元素之和最大的行为第" maxi "行"

    End Sub