VB编程,有一个n × m的矩阵,其各元素的值由随机函数生成(范围50~150)。编写程序,找出其中最大的元素
3个回答
展开全部
Lz,这些多练习练习就会了...
Option Base 1
Private Sub Command1_Click()
Dim i As Integer, j As Integer, s As String
Dim n As Integer, m As Integer
Dim a() As Integer, px As Integer, py As Integer
s = InputBox("输入矩阵行数n:", "输入", 4)
If s = "" Then Exit Sub
n = Val(s)
If n <= 0 Then
MsgBox "输入的数据有误!", vbOKOnly, "提示"
Exit Sub
End If
s = InputBox("输入矩阵列数m:", "输入", 4)
If s = "" Then Exit Sub
m = Val(s)
If m <= 0 Then
MsgBox "输入的数据有误!", vbOKOnly, "提示"
Exit Sub
End If
ReDim a(n, m)
Randomize
px = 1: py = 1
For i = 1 To n
For j = 1 To m
a(i, j) = Int(Rnd * 101 + 50)
Print CStr(a(i, j)) & " ";
If a(i, j) > a(px, py) Then px = i: py = j
Next j
Print
Next i
Print "最大的元素是:" & CStr(a(px, py)) & " 所在第" & CStr(px) & "行,第" & CStr(py) & "列"
End Sub
Option Base 1
Private Sub Command1_Click()
Dim i As Integer, j As Integer, s As String
Dim n As Integer, m As Integer
Dim a() As Integer, px As Integer, py As Integer
s = InputBox("输入矩阵行数n:", "输入", 4)
If s = "" Then Exit Sub
n = Val(s)
If n <= 0 Then
MsgBox "输入的数据有误!", vbOKOnly, "提示"
Exit Sub
End If
s = InputBox("输入矩阵列数m:", "输入", 4)
If s = "" Then Exit Sub
m = Val(s)
If m <= 0 Then
MsgBox "输入的数据有误!", vbOKOnly, "提示"
Exit Sub
End If
ReDim a(n, m)
Randomize
px = 1: py = 1
For i = 1 To n
For j = 1 To m
a(i, j) = Int(Rnd * 101 + 50)
Print CStr(a(i, j)) & " ";
If a(i, j) > a(px, py) Then px = i: py = j
Next j
Next i
Print "最大的元素是:" & CStr(a(px, py)) & " 所在第" & CStr(px) & "行,第" & CStr(py) & "列"
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Form_Click()
Dim a() As Integer
Dim i, j, max, n, m
Randomize(time)
n = InputBox("n=")
m = InputBox("m=")
ReDim a(n, m)
max = 0
For i = 1 To n
For j = 1 To m
a(i, j) = Int(Rnd() * 100) + 50
If a(i, j) > max Then max = a(i, j)
Next j
Next i
Print max
End Sub
Dim a() As Integer
Dim i, j, max, n, m
Randomize(time)
n = InputBox("n=")
m = InputBox("m=")
ReDim a(n, m)
max = 0
For i = 1 To n
For j = 1 To m
a(i, j) = Int(Rnd() * 100) + 50
If a(i, j) > max Then max = a(i, j)
Next j
Next i
Print max
End Sub
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
数组dim a(n,m) dim a
a=a(0,0)
for i=0 to n
for j=0 to m
if a(i,,j)>a then a=a(i,j)
next
next
print a
a=a(0,0)
for i=0 to n
for j=0 to m
if a(i,,j)>a then a=a(i,j)
next
next
print a
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询