急求!VB编程问题:有一个n×m的矩阵,编写程序,找出其中最大的元素所在的行和列,并输出其值及行号和列
提示:假设矩阵第一个元素为最大值,采用嵌套For循环遍历数组元素与第一个元素比较,若有比最大值大的元素就替换并标记行号和列号,循环结束即找出最大值。求技术帝解答!正确加分...
提示:假设矩阵第一个元素为最大值,采用嵌套For循环遍历数组元素与第一个元素比较,若有比最大值大的元素就替换并标记行号和列号,循环结束即找出最大值。
求技术帝解答!
正确加分! 展开
求技术帝解答!
正确加分! 展开
2014-05-18
展开全部
'新建一个工程,在form中添加一个按钮,按钮中写上以下代码即可
Private Sub Command1_Click()
Dim n As Long, m As Long
Dim i As Long, j As Long
Dim x As Long, y As Long, z As Long
Dim a() As Long
n = Val(InputBox("输入N", "输入N", 1))
m = Val(InputBox("输入M", "输入M", 1))
If n < 1 And m < 1 Then Exit Sub
ReDim a(n - 1, m - 1)
Randomize Timer
For i = 0 To n - 1
For j = 0 To m - 1
a(i, j) = Int(Rnd() * (n * m))
If z < a(i, j) Then
x = i + 1
y = j + 1
z = a(i, j)
End If
Next
Next
Cls
For i = 0 To n - 1
For j = 0 To m - 1
Print Space(5 - Len(CStr(a(i, j)))) & a(i, j);
Next
Print
Next
Print "最大值:" & z
Print "行:" & x
Print "列:" & y
End Sub
Private Sub Command1_Click()
Dim n As Long, m As Long
Dim i As Long, j As Long
Dim x As Long, y As Long, z As Long
Dim a() As Long
n = Val(InputBox("输入N", "输入N", 1))
m = Val(InputBox("输入M", "输入M", 1))
If n < 1 And m < 1 Then Exit Sub
ReDim a(n - 1, m - 1)
Randomize Timer
For i = 0 To n - 1
For j = 0 To m - 1
a(i, j) = Int(Rnd() * (n * m))
If z < a(i, j) Then
x = i + 1
y = j + 1
z = a(i, j)
End If
Next
Next
Cls
For i = 0 To n - 1
For j = 0 To m - 1
Print Space(5 - Len(CStr(a(i, j)))) & a(i, j);
Next
Next
Print "最大值:" & z
Print "行:" & x
Print "列:" & y
End Sub
2014-05-18
展开全部
是是是
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询