Dim a(5, 5) As Integer
Dim str As String
Private Sub Command1_Click()
Print "初始矩阵为:" & vbCrLf
For i = 1 To 5
For j = 1 To 5
a(i, j) = Int(Rnd * 8) + 1
Next j
Next i
For i = 1 To 5
If a(i, 6 - i) Mod 2 = 0 Then
a(i, 6 - i) = a(i, 6 - i) + 1
End If
Next i
For i = 1 To 4
If a(i, 5 - i) Mod 2 <> 0 Then
a(i, 5 - i) = a(i, 5 - i) + 1
End If
Next i
For i = 2 To 5
If a(i, 7 - i) Mod 2 = 0 Then
a(i, 7 - i) = a(i, 7 - i) + 1
End If
Next i
For i = 1 To 5
For j = 1 To 5
str = str & a(i, j) & " "
Next j
str = str & vbCrLf
Next i
Print str
End Sub
Private Sub Command2_Click()
Print "交换后的矩阵为:"
str = ""
Dim temp As Integer
For i = 1 To 4
For j = i To 1 Step -1
temp = a(5 - i, j)
a(5 - i, j) = a(6 - j, i + 1)
a(6 - j, i + 1) = temp
Next j
Next i
For i = 1 To 5
For j = 1 To 5
str = str & a(i, j) & " "
Next j
str = str & vbCrLf
Next i
Print str
End Sub
温馨提示:答案为网友推荐,仅供参考