visual basic代码怎么对二维矩阵进行副对角线进行反转?
发布网友
发布时间:2022-04-25 12:00
我来回答
共1个回答
热心网友
时间:2024-07-11 03:20
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