很简单的,使用判断语句将可以了。
Dim mm(1 To 5, 1 To 5) As Integer
Private Sub Command1_Click()
Text1.Text = ""
For i = 1 To 5
For j = 1 To 5
Randomize
If j < i Then
mm(i, j) = 1
Text1.Text = Text1.Text & Space(5) & mm(i, j)
Else
mm(i, j) = Int(Rnd * 90 + 10)
Text1.Text = Text1.Text & Space(3) & mm(i, j)
End If
Next j
Text1.Text = Text1.Text & vbCrLf
Next i
End Sub
Private Sub Command1_Click()
Dim a(5, 5) As Integer
For i = 1 To 5
For j = 1 To 5
If i + j > 6 Then
a(i, j) = 1
Else
a(i, j) = Int(Rnd * 10) + 10
End If
Print Tab(4 * j); a(i, j);
Next j
Next i
End Sub
建议是,先产生一个5..49的随机矩阵,然后副对角线上方都乘2,其余元素乘2加1。
给你一句matlab的代码,可以做好
>> randi([5,49],5)*2+fliplr(tril(ones(5)))
ans =
90 76 64 30 99
40 54 86 89 75
72 52 83 13 55
26 91 61 55 53
13 65 27 25 15
>> randi([5,49],5)*2+fliplr(tril(ones(5)))
ans =
70 82 56 48 45
12 82 96 85 85
16 74 69 17 83
56 23 83 21 15
19 69 51 25 45