VB试题随机产生20个50-108(包括50和108)的整数赋给一个一维数组,求其最大值,
5个回答
展开全部
工具/材料:以Microsoft Visual Studio 2010为例。
1、首先在桌面上,点击“Microsoft Visual Studio 2010”图标。
2、然后在该界面中,输入随机产生20个50-108(包括50和108)的整数赋给一个一维数组的代码“Dim arr(1 To 20) As Integer Dim max As Integer For i = 1 To 20 arr(i) = Int(Rnd() * 58 + 50)”。
4、最后在该界面中,输入求其最大值的代码“For i = 1 To 20 If max < arr(i) Then max = arr(i) End If”。
展开全部
Sub Test()
Dim arr(19) As Integer
For i = LBound(arr) To UBound(arr)
arr(i) = Int((59 * Rnd)) + 50
arrstr = arrstr & " " & arr(i)
If arr(i) > maxNum Then maxNum = arr(i)
Next
MsgBox arrstr & Chr(10) & " Max=" & maxNum
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Form_Load()
Label1.Caption = ""
Dim arr(1 To 20) As Integer
Dim max As Integer
For i = 1 To 20
arr(i) = Int(Rnd() * 58 + 50)
Label1.Caption = arr(i) & "_" & Label1.Caption
Next
For i = 1 To 20 '这是找最大值的简单程序
If max < arr(i) Then
max = arr(i)
End If
Next
Label1.Caption = "最大数值为:" & max & " " & vbCrLf & "原始数据为:" & Label1.Caption & vbCrLf & "排序后为:"
For i = 2 To 20
temp = arr(i)
j = i - 1
Do Until temp < arr(j)
arr(j + 1) = arr(j)
j = j - 1
If j = 0 Then
Exit Do
End If
Loop
arr(j + 1) = temp
Next i
For i = 1 To 20
Label1.Caption = Label1.Caption & arr(i) & " - "
Next i
End Sub
Label1.Caption = ""
Dim arr(1 To 20) As Integer
Dim max As Integer
For i = 1 To 20
arr(i) = Int(Rnd() * 58 + 50)
Label1.Caption = arr(i) & "_" & Label1.Caption
Next
For i = 1 To 20 '这是找最大值的简单程序
If max < arr(i) Then
max = arr(i)
End If
Next
Label1.Caption = "最大数值为:" & max & " " & vbCrLf & "原始数据为:" & Label1.Caption & vbCrLf & "排序后为:"
For i = 2 To 20
temp = arr(i)
j = i - 1
Do Until temp < arr(j)
arr(j + 1) = arr(j)
j = j - 1
If j = 0 Then
Exit Do
End If
Loop
arr(j + 1) = temp
Next i
For i = 1 To 20
Label1.Caption = Label1.Caption & arr(i) & " - "
Next i
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Dim i%, n%, m%
Dim a() As Integer
n = 10
For i = 1 To n
a(i) = 50 + Rnd * (108 - 50 + 1)
Next
m = 0
For i = 1 To n
If m < a(i) Then m = a(i)
Next
Print m
End Sub
Dim i%, n%, m%
Dim a() As Integer
n = 10
For i = 1 To n
a(i) = 50 + Rnd * (108 - 50 + 1)
Next
m = 0
For i = 1 To n
If m < a(i) Then m = a(i)
Next
Print m
End Sub
追问
运行的时候不对啊
追答
在n=10下面加一句 redim a(n) as integer
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询