...20个50-108(包括50和108)的整数赋给一个一维数组,求其最大值,_百度...
发布网友
发布时间:2024-10-03 20:51
我来回答
共5个回答
热心网友
时间:2024-10-09 00:57
工具/材料:以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”。
热心网友
时间:2024-10-09 01:00
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
热心网友
时间:2024-10-09 00:53
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
热心网友
时间:2024-10-09 00:58
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
Print
End Sub
热心网友
时间:2024-10-09 01:00
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