用VB做:通过随机产生20到40之间的整数形成4*5的矩阵,然后按行递减次序排列
用VB做:通过随机产生20到40之间的整数形成4*5的矩阵,然后按行递减次序排列
Option Base 1
Dim a(4,5) As Integer
Private Sub Command1_Click()
Dim i As Integer,j As Integer
For i = 1 To 4
For j = 1 To 5
Randomize
a(i,j) = Int(Rnd * 9 + 1)
Picture1.Print a(i,j);
Next j
Picture1.Print
Next i
End Sub
Private Sub Command2_Click()
Dim max As Integer,min As Integer,max_i As Integer,min_i As Integer,s As String
max = 0
min = 9999
For i = 1 To 4
Sum = 0
For j = 1 To 5
Sum = Sum + a(i,j)
Next j
s = s + Str(Sum) + vbCrLf
Text2.Text = s
If Sum > max Then
max = Sum
max_i = i
End If
If Sum < min Then
min = Sum
min_i = i
End If
Next i
Text1.Text = Str(max_i) & Str(min_i)
For j = 1 To 5
temp = a(max_i,j)
a(max_i,j) = a(min_i,j)
a(min_i,j) = temp
Next j
For i = 1 To 4
For j = 1 To 5
Picture2.Print a(i,j);
Next j
Picture2.Print
Next i
End Sub
更详细说明见
另外,站长团上有产品团购,便宜有保证