求VB编程:给一个5*5的矩阵赋值,要求矩阵副对角线上方元素都是偶数,副对...
发布网友
发布时间:2024-10-23 09:36
我来回答
共2个回答
热心网友
时间:2024-11-15 01:16
Private Sub Command1_Click()
Dim mArr(1 To 5, 1 To 5), r%, c%, tmp%
For r = 1 To 5
For c = 1 To 5
Randomize
tmp = Int(Rnd * 90) + 10
If c > r Then
Do While tmp Mod 2 = 1
Randomize
tmp = Int(Rnd * 90) + 10
Loop
Else
Do While tmp Mod 2 = 0
Randomize
tmp = Int(Rnd * 90) + 10
Loop
End If
mArr(r, c) = tmp
Print mArr(r, c);
Next c
Print
Next r
End Sub
热心网友
时间:2024-11-15 01:14
Private Sub Command1_Click()
Dim a(1 To 5, 1 To 5)
Randomize
For i = 1 To 5
For j = 1 To 5
If i >= j Then
a(i, j) = 2 * Int(40 * Rnd) + 11
Else
a(i, j) = 2 * Int(40 * Rnd + 5)
End If
Next j, i
For i = 1 To 5
For j = 1 To 5
Print a(i, j);
Next j
Print
Next i
End Sub