求大佬解决一个VB问题
求一个m*n矩阵中的最大值、最小值及其所在的行、列并输出。m和n由InputBox函数给出,矩阵中的元素值随机生成,...
求一个m*n矩阵中的最大值、最小值及其所在的行、列并输出。m和n由InputBox函数给出,矩阵中的元素值随机生成,
展开
1个回答
展开全部
Private Sub Command1_Click()
Dim m As Integer, n As Integer
m = InputBox("请输入矩阵的行数:")
n = InputBox("请输入矩阵的列数:")
Dim a(20, 20) As Integer
m1 = 1: n1 = 1: m2 = 1: n2 = 1
Randomize
For i = 1 To m
For j = 1 To n
a(i, j) = Rnd * 90 + 10
Print a(i, j);
If a(i, j) > a(m1, n1) Then m1 = i: n1 = j
If a(i, j) < a(m2, n2) Then m2 = i: n2 = j
Next j
Print
Next i
Print
Print "最大值: A(" & m1 & "," & n1 & ")=" & a(m1, n1)
Print "最小值: A(" & m2 & "," & n2 & ")=" & a(m2, n2)
End Sub
更多追问追答
追答
那再加一行试试?
Dim m1 As Integer,m2 As Integer,n1 As Integer,n2 As Integer,i As Integer,j As Integer
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询