急求vb 5*5矩阵,数值30-70,求主对角线和副对角线之和,及其转置矩阵
发布网友
发布时间:2024-10-23 09:36
我来回答
共1个回答
热心网友
时间:2024-11-04 06:24
干嘛急? 呵呵
简单
form上 放一个 文本框(多行,垂直滚动条)和一个 按钮
Private Sub Command1_Click()
Dim a(4, 4) As Integer
Dim i, j As Integer
Dim sumx, sumy As Integer
Randomize
sumx = 0
sumy = 0
Text1.Text = Text1.Text + "原矩阵:" + vbCrLf
For i = 0 To 4
For j = 0 To 4
a(i, j) = Int((70 - 30 + 1) * Rnd + 30)
Text1.Text = Text1.Text + CStr(a(i, j)) + " "
Next
Text1.Text = Text1.Text + vbCrLf
Next
Text1.Text = Text1.Text + vbCrLf
Text1.Text = Text1.Text + "主对角线的和:" + vbCrLf
For i = 0 To 4
sumx = sumx + a(i, i)
sumy = sumy + a(i, 4 - i)
Next
Text1.Text = Text1.Text + CStr(sumx) + vbCrLf
Text1.Text = Text1.Text + "副对角线的和:" + vbCrLf
Text1.Text = Text1.Text + CStr(sumy) + vbCrLf
Text1.Text = Text1.Text + vbCrLf
Text1.Text = Text1.Text + "转置矩阵:" + vbCrLf
For i = 0 To 4
For j = 0 To 4
Text1.Text = Text1.Text + CStr(a(j, i)) + " "
Next
Text1.Text = Text1.Text + vbCrLf
Next
End Sub