用随机函数生成一个6 行6列的整型数组(数据在100内),找出某个指定行内最大元素所在的列号.Private Sub Form_Click()Dim a(6,6) As IntegerFor j = 1 To 6For i = 1 To 6a(i,j) = Int(100 * Rnd)NextNextj = Val(InputBox("输

来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/29 12:14:54
用随机函数生成一个6行6列的整型数组(数据在100内),找出某个指定行内最大元素所在的列号.PrivateSubForm_Click()Dima(6,6)AsIntegerForj=1To6Fori=

用随机函数生成一个6 行6列的整型数组(数据在100内),找出某个指定行内最大元素所在的列号.Private Sub Form_Click()Dim a(6,6) As IntegerFor j = 1 To 6For i = 1 To 6a(i,j) = Int(100 * Rnd)NextNextj = Val(InputBox("输
用随机函数生成一个6 行6列的整型数组(数据在100内),找出某个指定行内最大元素所在的列号.
Private Sub Form_Click()
Dim a(6,6) As Integer
For j = 1 To 6
For i = 1 To 6
a(i,j) = Int(100 * Rnd)
Next
Next
j = Val(InputBox("输入1-6之间的整数"))
i = fact(m)
MsgBox "第" & j & "行最大的数的列数为" & i
End Sub
Function fact(m) As Long
Dim a(6,6) As Integer
For n = 1 To 6
For m = 1 To 6
a(m,n) = Int(100 * Rnd)
Next
Next
For n = 1 To 6
Max = a(1,n)
For m = 1 To 6
If Max < a(m,n) Then
Max = a(m,n)
fact = m
End If
Next
Next
End Function
以上为代码,不知哪错了

用随机函数生成一个6 行6列的整型数组(数据在100内),找出某个指定行内最大元素所在的列号.Private Sub Form_Click()Dim a(6,6) As IntegerFor j = 1 To 6For i = 1 To 6a(i,j) = Int(100 * Rnd)NextNextj = Val(InputBox("输
Dim a(6, 6) As Integer//定义在方法外面即全局变量
Private Sub Form_Click()
For j = 1 To 6
For i = 1 To 6
a(i, j) = Int(100 * Rnd)
Next
Next
j = Val(InputBox("输入1-6之间的整数"))
i = fact(j)
MsgBox "第" & j & "行最大的数的列数为" & i
End Sub
Function fact(m) As Long
//这里不能重新为数组元素赋值,应该用原来的
Max = a(m,1)//只求一个行的,所以用单循环即可
For n = 1 To 6
If Max < a(m, n) Then
Max = a(m, n)
fact =n
End If
Next
Next
End Function