vb.net ---- n*n随机矩阵转换

前端之家收集整理的这篇文章主要介绍了vb.net ---- n*n随机矩阵转换前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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


效果图:

猜你在找的VB相关文章