n*n矩阵 以对角线实现矩阵转换
Public Class Form1 Dim a(4,4) As Integer Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button1.Click Dim i,j,t As Integer For i = 1 To 3 For j = 0 To i - 1 t = a(i,j) a(i,j) = a(j,i) a(j,i) = t Next Next Label2.Text = "转置后矩阵" & Chr(13) & Chr(10) For i = 0 To 3 For j = 0 To 3 Label2.Text = Label2.Text & a(i,j) & " " Next Label2.Text = Label2.Text & Chr(13) & Chr(10) Next End Sub Private Sub Button2_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button2.Click Dim i As Integer,j As Integer Randomize() For i = 0 To 3 For j = 0 To 3 a(i,j) = Fix(Rnd() * 90 + 10) Next Next Label1.Text = "原矩阵为" & Chr(13) & Chr(10) For i = 0 To 3 For j = 0 To 3 Label1.Text = Label1.Text & a(i,j) & " " Next Label1.Text = Label1.Text & Chr(13) & Chr(10) Next End Sub End Class
效果图: