求解一道VB程序设计题:定义一个二维数组a,共4行4列。要求如下。
求解一道VB程序设计题:定义一个二维数组a,共4行4列。要求:(1)用随机函数产生[50,100]范围内的随机整数,并赋值给数组元素,并把改数组以4行4列的形式显示在窗体...
求解一道VB程序设计题:定义一个二维数组a,共4行4列。要求:(1)用随机函数产生[50,100]范围内的随机整数,并赋值给数组元素,并把改数组以4行4列的形式显示在窗体上。(2)求出数组的最大值max,最小值min,以及它们所对应的下标,并显示在窗体上。(3)求出数组元素的总和sum、平均值ave,并显示在窗体上。
展开
2个回答
展开全部
Private Sub Command1_Click()
Dim abc(3, 3) As Integer
Dim abcMax As Integer
Dim abcMin As Integer
Dim i As Integer
Dim j As Integer
Dim iMax As Integer
Dim jMax As Integer
Dim iMin As Integer
Dim jMin As Integer
Dim abcSum As Integer
Dim abcAve As Single
For i = 0 To 3
For j = 0 To 3
abc(i, j) = 50 + Int(Rnd(1) * 50)
Next j
Next i
abcMax = 0
abcMin = 100
For i = 0 To 3
For j = 0 To 3
If abc(i, j) > abcMax Then
abcMax = abc(i, j)
iMax = i
jMax = j
End If
If abc(i, j) < abcMin Then
abcMin = abc(i, j)
iMin = i
jMin = j
End If
Next j
Next i
abcSum = 0
For i = 0 To 3
For j = 0 To 3
abcSum = abcSum + abc(i, j)
Next j
Next i
abcAve = abcSum / 16
Me.FontSize = 20
For i = 0 To 3
For j = 0 To 3
Me.Print abc(i, j),
Next j
Me.Print
Next i
Me.Print "Max", iMax, jMax, abcMax
Me.Print "Min", iMin, jMin, abcMin
Me.Print "Sum", abcSum
Me.Print "Ave", abcAve
End Sub
Dim abc(3, 3) As Integer
Dim abcMax As Integer
Dim abcMin As Integer
Dim i As Integer
Dim j As Integer
Dim iMax As Integer
Dim jMax As Integer
Dim iMin As Integer
Dim jMin As Integer
Dim abcSum As Integer
Dim abcAve As Single
For i = 0 To 3
For j = 0 To 3
abc(i, j) = 50 + Int(Rnd(1) * 50)
Next j
Next i
abcMax = 0
abcMin = 100
For i = 0 To 3
For j = 0 To 3
If abc(i, j) > abcMax Then
abcMax = abc(i, j)
iMax = i
jMax = j
End If
If abc(i, j) < abcMin Then
abcMin = abc(i, j)
iMin = i
jMin = j
End If
Next j
Next i
abcSum = 0
For i = 0 To 3
For j = 0 To 3
abcSum = abcSum + abc(i, j)
Next j
Next i
abcAve = abcSum / 16
Me.FontSize = 20
For i = 0 To 3
For j = 0 To 3
Me.Print abc(i, j),
Next j
Me.Print
Next i
Me.Print "Max", iMax, jMax, abcMax
Me.Print "Min", iMin, jMin, abcMin
Me.Print "Sum", abcSum
Me.Print "Ave", abcAve
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Dim x(3, 3) As Integer
For i = 0 To 3
For j = 0 To 3
x(i, j) = 50 + Int(Rnd() * 51)
Next j
Next i
Cls
For i = 0 To 3
For j = 0 To 3
Print x(i, j),
Next j
Print
Next i
'------------------
Max = x(0, 0)
pmxi = 0
pmxj = 0
'------------------
Min = x(0, 0)
pnxi = 0
pnxj = 0
Sum = 0
For i = 0 To 3
For j = 0 To 3
Sum = Sum + x(i, j)
If x(i, j) > Max Then
Max = x(i, j)
pmxi = i
pmxj = j
End If
Next j
Print
Next i
For i = 0 To 3
For j = 0 To 3
If x(i, j) < Min Then
Min = x(i, j)
pnxi = i
pnxj = j
End If
Next j
Print
Next i
Print Max, pmxi, pmxj
Print Min, pnxi, pnxj
Print Sum, Sum / 16
End Sub
Dim x(3, 3) As Integer
For i = 0 To 3
For j = 0 To 3
x(i, j) = 50 + Int(Rnd() * 51)
Next j
Next i
Cls
For i = 0 To 3
For j = 0 To 3
Print x(i, j),
Next j
Next i
'------------------
Max = x(0, 0)
pmxi = 0
pmxj = 0
'------------------
Min = x(0, 0)
pnxi = 0
pnxj = 0
Sum = 0
For i = 0 To 3
For j = 0 To 3
Sum = Sum + x(i, j)
If x(i, j) > Max Then
Max = x(i, j)
pmxi = i
pmxj = j
End If
Next j
Next i
For i = 0 To 3
For j = 0 To 3
If x(i, j) < Min Then
Min = x(i, j)
pnxi = i
pnxj = j
End If
Next j
Next i
Print Max, pmxi, pmxj
Print Min, pnxi, pnxj
Print Sum, Sum / 16
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询