mtwm.net
当前位置:首页 >> VB从数组中找出最大最小值及其位置代码 >>

VB从数组中找出最大最小值及其位置代码

查找数组中的最大值、最小值 及其位置Private Sub Command1_Click() Dim I As Long, Zu() As Single, nMax As Long, nMin As Long, nStr As String ReDim Zu(1 To 10) For I = 1 To 10 Randomize: Zu(I) = Int(100 * Rnd) nStr = nStr & Zu(I) & ","

dim a(0 to 99) as integer, amin as integer, i as integer, imin as integer amin = 65536 for i = 0 to 99 if amin > a(i) then amin = a(i) imin = i end if next debug.print amin, imin

dim str as stringdim str1 as new strdim max,i,n as integer max=0n=0 'n用于记录位置'随机分配两位数的数组for i=0 to str1.length str1[i]=Sint(rnd()*10+90)end for'对数组进行排序for i=0 to str1.length if max<str1[i] then max=str1[i] n=i end ifend for

在你基础上,我加了几句代码就可以了: Private Sub Command1_Click() Cls Dim a(1 To 10) As Integer, b(1 To 10) As Integer, work As Boolean, i As Integer, j As Integer, x As Integer Randomize For i = 1 To 10 a(i) = Int((90 * Rnd) + 10) Print a(i)

很简单for i=0 to 5a(i)=inputbox("输入任意数",找最值)next imax=a(0)max_j=0 for j=1 to 5 if(a(j)&gt;max) then max=a(j) max_j=jendifnext jprint max max_j这个就是的上面的&gt;改成 &lt;就是找最小值了

如果有几个最大值咋办? dim iTest(n) as integerdim iplace(n) as integerdim max as integerdim i as integerdim j as integerfor i= 0 to n-1 if iTest(i)>iTest(i+1) then max = iTest(i) else max = iTest(i+1) end ifnextfor i= 0 to n if iTest(i)=max then iplace(j) = i end if j=j+1next最大值:max位置:iplace()

function GetData() dim Max as double '最大的数 dim min as double '最小的数 dim iL as double '最大的位置 dim al as double '最小的位置 dim total as double '合计 dim a(4) a(0)=textbox1.text a(1)=textbox2.text a(2)=textbox3.text a(3)=textbox4.

Option Base 1 Private Sub Command1_Click() Dim s(10) As Integer Dim Max As Integer, maxi As Integer, Min As Integer, mini As Integer s(1) = Val(InputBox("请输入第1个元素")) Min = s(1): mini = 1: Max =

Private Sub Form_Click() Form1.AutoRedraw = True Dim A() Dim I As Integer, J As Integer, N As Integer Dim MinG As Integer, MaxG As Integer A = Array(0, 0, 3, 4, 12, 11, 34, 34, 34, 34) For I = 0 To UBound(A) - 1 For J = I To UBound(A) If A(I) >

这是我自己写的 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i As Integer Dim temptext, loca As Integer Dim str As String = TextBox1.Text Dim substr As String Dim array(4)

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