VB试题随机产生20个50-108(包括50和108)的整数赋给一个一维数组,求其最大值,
答案:4 悬赏:70 手机版
解决时间 2021-03-29 09:01
- 提问者网友:谁的错
- 2021-03-28 21:23
VB试题随机产生20个50-108(包括50和108)的整数赋给一个一维数组,求其最大值,
最佳答案
- 五星知识达人网友:话散在刀尖上
- 2021-03-28 21:31
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追问运行的时候不对啊追答在n=10下面加一句 redim a(n) as integer
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
全部回答
- 1楼网友:一叶十三刺
- 2021-03-28 23:42
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
- 2楼网友:深街酒徒
- 2021-03-28 22:48
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
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
- 3楼网友:行路难
- 2021-03-28 21:43
Private Sub Command1_Click()
Dim a(20) As Integer
Randomize
Max = -1
For i = 1 To 20
a(i) = 50 + Int(Rnd * 59)
Print a(i);
If i Mod 10 = 0 Then Print
If Max < a(i) Then Max = a(i)
Next i
Print "Max="; Max
End Sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯