vb编程利用随机数生成两个矩阵(数据不一定相同,前者范围为30~90,后者为101~135) 要求 1.将两个矩阵结果放

1个回答

  • Option Explicit

    Sub SShow(A() As Integer)

    Dim I, J

    For I = 1 To 4

    For J = 1 To 4

    Print A(I, J);

    Next

    Print

    Next

    End Sub

    Private Sub Form_Click()

    Dim A(1 To 4, 1 To 4) As Integer

    Dim B(1 To 4, 1 To 4) As Integer

    Dim I As Integer, J As Integer, T As Integer

    Dim L As Integer, U As Integer

    L = 30

    U = 70

    Randomize

    For I = 1 To 4

    For J = 1 To 4

    A(I, J) = Int((U - L + 1) * Rnd + L)

    Next

    Next

    L = 101

    U = 135

    Randomize

    For I = 1 To 4

    For J = 1 To 4

    B(I, J) = Int((U - L + 1) * Rnd + L)

    Next

    Next

    Print "A:"

    SShow A

    Print "B:"

    SShow B

    Dim C(1 To 4, 1 To 4) As Integer

    For I = 1 To 4

    For J = 1 To 4

    C(I, J) = A(I, J) + B(I, J)

    Next

    Next

    Print "C:"

    SShow C

    For I = 1 To 4

    For J = I To 4

    T = A(I, J): A(I, J) = A(J, I): A(J, I) = T

    Next

    Next

    Print "A':"

    SShow A

    Dim R1, C1, Max

    Max = C(1, 1)

    For I = 1 To 4

    For J = 1 To 4

    If Max < C(I, J) Then

    Max = C(I, J)

    R1 = I

    C1 = J

    End If

    Next

    Next

    Print "C: MAX=" & Max & " 行:" & R1 & " 列:" & C1

    Print "A:"

    For I = 1 To 4

    For J = 1 To I

    Print A(I, J);

    Next

    Print

    Next

    Print "B:"

    For I = 1 To 4

    Print Space((I - 1) * 5);

    For J = I To 4

    Print B(I, J);

    Next

    Print

    Next

    For J = 1 To 4

    T = B(1, J): B(1, J) = B(3, J): B(3, J) = T

    Next

    Print "B:"

    SShow B

    End Sub

    这个问题你可以去搜索一下编,程,回,忆,录,之unity3d.零基础开始学起,就算是菜鸟都能看懂