VB编写程序生成一个4行5列的二维数组,并求该数组的最大元素及其行号、列号。。
VB,编写程序,生成一个4行5列的二维数组,其每个数组元素是随机产生的两位数,并求该数组的最大元素及其所在的行号、列号。。要求:运行程序,按“运行”按钮,在文本框里生成一...
VB,编写程序,生成一个4行5列的二维数组,其每个数组元素是随机产生的两位数,并求该数组的最大元素及其所在的行号、列号。。要求:运行程序,按“运行”按钮,在文本框里生成一个4行5列的两位随机整数数组,再调用求二维数组最大元素及其所在行号、列号(若有多个相同的最大元素,则要一一标出其所在行号、列号)的通用过程,结果输出在一个图片框内。。谢谢!!
展开
2个回答
展开全部
Dim Suju(3, 4) As Integer
Private Sub Command1_Click()
Randomize
Text1 = ""
For i = 0 To 3
For j = 0 To 4
Suju(i, j) = Rnd * 89 + 10
Text1 = Text1 & " " & Suju(i, j)
Next
Text1 = Text1 & vbCrLf
Next
Picture1.Cls
Picture1.Print Smax(Suju)
End Sub
Function Smax(Sj() As Integer) As String
Dim aa As Integer
Dim bb As String
aa = Suju(0, 0)
For i = 0 To UBound(Sj, 1)
For j = 0 To UBound(Sj, 2)
If aa < Sj(i, j) Then aa = Sj(i, j)
Next
Next
For i = 0 To UBound(Sj, 1)
For j = 0 To UBound(Sj, 2)
If aa = Sj(i, j) Then
bb = bb & vbCrLf & "在第" & i + 1 & "行,第" & j + 1 & "列"
End If
Next
Next
Smax = "最大值是:" & aa & bb
End Function
Private Sub Command1_Click()
Randomize
Text1 = ""
For i = 0 To 3
For j = 0 To 4
Suju(i, j) = Rnd * 89 + 10
Text1 = Text1 & " " & Suju(i, j)
Next
Text1 = Text1 & vbCrLf
Next
Picture1.Cls
Picture1.Print Smax(Suju)
End Sub
Function Smax(Sj() As Integer) As String
Dim aa As Integer
Dim bb As String
aa = Suju(0, 0)
For i = 0 To UBound(Sj, 1)
For j = 0 To UBound(Sj, 2)
If aa < Sj(i, j) Then aa = Sj(i, j)
Next
Next
For i = 0 To UBound(Sj, 1)
For j = 0 To UBound(Sj, 2)
If aa = Sj(i, j) Then
bb = bb & vbCrLf & "在第" & i + 1 & "行,第" & j + 1 & "列"
End If
Next
Next
Smax = "最大值是:" & aa & bb
End Function
展开全部
Private Sub Command1_Click()
Randomize
Text1 = ""
For i = 0 To 3
For j = 0 To 4
Suju(i, j) = Rnd * 89 + 10
Text1 = Text1 & " " & Suju(i, j)
Next
Text1 = Text1 & vbCrLf
Next
Picture1.Cls
Picture1.Print Smax(Suju)
End Sub
Function Smax(Sj() As Integer) As String
Dim aa As Integer
Dim bb As String
aa = Suju(0, 0)
For i = 0 To UBound(Sj, 1)
For j = 0 To UBound(Sj, 2)
If aa < Sj(i, j) Then aa = Sj(i, j)
Next
Next
For i = 0 To UBound(Sj, 1)
For j = 0 To UBound(Sj, 2)
If aa = Sj(i, j) Then
bb = bb & vbCrLf & "在第" & i + 1 & "行,第" & j + 1 & "列"
End If
Next
Next
Smax = "最大值是:" & aa & bb
Randomize
Text1 = ""
For i = 0 To 3
For j = 0 To 4
Suju(i, j) = Rnd * 89 + 10
Text1 = Text1 & " " & Suju(i, j)
Next
Text1 = Text1 & vbCrLf
Next
Picture1.Cls
Picture1.Print Smax(Suju)
End Sub
Function Smax(Sj() As Integer) As String
Dim aa As Integer
Dim bb As String
aa = Suju(0, 0)
For i = 0 To UBound(Sj, 1)
For j = 0 To UBound(Sj, 2)
If aa < Sj(i, j) Then aa = Sj(i, j)
Next
Next
For i = 0 To UBound(Sj, 1)
For j = 0 To UBound(Sj, 2)
If aa = Sj(i, j) Then
bb = bb & vbCrLf & "在第" & i + 1 & "行,第" & j + 1 & "列"
End If
Next
Next
Smax = "最大值是:" & aa & bb
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询