vb编程求矩阵A中每一列的最大值以及最大值所在的行
2个回答
2011-05-06
展开全部
'新建一个工程,在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
另外,团IDC网上有许多产品团购,便宜有口碑
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
另外,团IDC网上有许多产品团购,便宜有口碑
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询