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

大一vb作业随机生成一个两位数4*4的矩阵,然后求出矩阵主对角元素之和

题目详情
大一vb作业
随机生成一个两位数4*4的矩阵,然后求出矩阵主对角元素之和
▼优质解答
答案和解析
Private Sub Command1_Click()
Dim i, j As Integer
i = 0
j = 0
Dim b As String
Dim a(3, 3) As Integer
For i = 0 To 3 Step 1
For j = 0 To 3 Step 1

a(i, j) = Rnd * 100
While a(i, j) < 10
a(i, j) = Rnd() * 100
Wend
b = b & a(i, j) & Space(2)
Next j
b = b + vbCrLf
Next i
Dim result As Integer
For i = 0 To 3 Step 1
For j = 0 To 3 Step 1
If i = j Then
result = result + a(i, j)

End If

Next j
Next i
Print b
Print "The Result is " & result
End Sub
看了 大一vb作业随机生成一个两位...的网友还看了以下: