从十个数中求出最大值 麻烦您写一下vb代码

来源:百度知道 编辑:UC知道 时间:2024/09/20 18:33:48
允许输入十个数字 然后显示最大值

'添加窗体Form1,按钮Command1,然后添加如下代码:
Private Sub Command1_Click()
    Dim a(9), i, temp As Integer
    For i = 0 To 9
        a(i) = Val(InputBox("请输入第" & i + 1 & "个数:"))
    Next
    temp = a(0)
    For i = 0 To 9
        If a(i) > temp Then temp = a(i)
    Next
    Print "最大数为:" & temp
End Sub

把10个数存入数组.

dim a(1 to 10) as integer,nMax%,i%
'产生10个数
for i=1 to 10
a(i)=int(Rnd*100)
next i
nmax=a(1)
for i=1 to 10
if a(i)>nmax then nmax=a(i)