blsn.net
当前位置:首页 >> 写VB程序:利用一维数组求最大值及其下标 >>

写VB程序:利用一维数组求最大值及其下标

dim A(1 to 10) as integer,i as integer,n as integer,max as integer randomize for i=1 to 10 a(i)=int(rnd()*100) '给数组赋值 next i max=a(1) n=1 for i=1 to 10 if a(i)>max then max=a(i) n=i end if next i print "最大值:";max;"下标...

设数组为a(10) dim temp as integer dim j as integer for i=0 to 10 if temp

窗体添加command1,然后拷贝下面代码 Dim a(4) As Integer Private Sub Command1_Click() Dim sum As Integer Dim i As Integer Dim maxItem As Integer For i = 0 To UBound(a()) If maxItem < a(i) Then maxItem = a(i) sum = sum + a(i) Next...

dim A(1 to 10) as integer,i as integer,n as integer,max as integer randomize for i=1 to 10 a(i)=int(rnd()*100) '给数组赋值 next i max=a(1) n=1 for i=1 to 10 if a(i)>max then max=a(i) n=i end if next i print "最大值:";max;"下标...

Private Sub Command1_Click() Cls Dim a(1 To 10) As Integer Dim xb As Integer, min As Integer For i = 1 To UBound(a) a(i) = Val(InputBox("请你输入第" & i & "个数", , "1")) Print a(i); Next i Print xb = 1: min = a(1) For i = 2 To...

Private Sub Form_Click()Dim a(10), max, i, jmax = -1For i = 1 To 10 a(i) = Int(Rnd * 100) Print a(i); If max < a(i) Then max = a(i): j = i ElseIf max = a(i) Then j = j & " " & i End IfNextPrintPrint "最大数是"; maxPrint "下标是...

Private Sub Command1_Click() Dim a(14) As Integer maxi = 0 For i = 0 To 14 a(i) = Int(Rnd * 100) If a(maxi) < a(i) Then maxi = i Print a(i); Next i Print t = a(0): a(0) = a(maxi): a(maxi) = t Print "对换以后:" For i = 0 To 14...

dim a(10) as integer dim max as integer,i as integer,j as integer ………… max=a(1):j=1 for i=2 to 10 if a(i)>max then max=a(i) j=i endif ?"最大值是:";max,"它是第“;j;“个元素"

Private Sub Form_Click() Dim a(1 To 10) Randomize '随机种子,保证每次出现随机数不一样 For i = 1 To 10 a(i) = Int(Rnd * 100) '随机生成0到99的整数 Print a(i); Next i Print maxnum = a(1) '初始最大值为随机数的第一个数 For i = 1 To ...

解: private sub command1_click() dim a(1 to 10) as double dim min as double for i=1 to 10 a(i)=val(inputbox("请输入数组元素值:")) next i for i=1 to 10 if a(i)

网站首页 | 网站地图
All rights reserved Powered by www.blsn.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com