早教吧 育儿知识 作业答案 考试题库 百科 知识分享

VB说下标越界,让先打印一个5*5的矩阵,在交换第二第四行.我的代码PrivateSubFormLoad()Dimmat(5,5)AsIntegerShowPrint"初始矩阵为:"Fori=1To5Forj=1To5mat(i,j)=Int(Rnd()*90+10)PrintTab(5*j);mat(i,j);N

题目详情
VB 说下标越界,让先打印一个5*5的矩阵,在交换第二第四行.
我的代码
Private Sub Form_Load()
Dim mat(5,5) As Integer
Show
Print "初始矩阵为:"
For i = 1 To 5
For j = 1 To 5
mat(i,j) = Int(Rnd() * 90 + 10)
Print Tab(5 * j); mat(i,j);
Next
Print
Next
Print "交换第二列和第四列后的矩阵为:"
For j = 1 To 5
t = mat(2,j)
mat(2,j) = mat(4,j)
mat(4,j) = t
Next
For i = 1 To 5
For j = 1 To 5
Print Tab(j * 5); mat(i,j);
Next
Print
Next
End Sub
▼优质解答
答案和解析
Print "交换第二列和第四列后的矩阵为:"
For j = 1 To 5
t = mat(2,j)
mat(2,j) = mat(4,j)
mat(4,j) = t
Next
For i = 1 To 5
For j = 1 To 5
Print Tab(j * 5); mat(i,j);
Next
Print
Next
End Sub