mdsk.net
当前位置:首页 >> VB数组找最大最小值问题. >>

VB数组找最大最小值问题.

Private Sub Form_Load() Dim i&, n&, a&(), maxb&, minb& n = InputBox("数组元素个数") ReDim a(n - 1) a(0) = InputBox("任意的数") maxb = 0: minb = 0 For i = 1 To n - 1 a(i) = InputBox("任意的数") If a(i) > a(maxb) Then maxb = i If...

查找数组中的最大值、最小值 及其位置 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) ...

代码及注释如下: sub main() dim a(0 to 99) as integer, amin as integer, i as integer, imin as integer x = 65536'定义变量x为一个比数组中最大值还要大的数 for i = 0 to 99'假设数组元素个数为100个 if x > a(i) then x= a(i)‘如果x大于...

vb没有max和min函数,需要自己编写 Private Sub Command1_Click() Dim arr(1 To 100) As Integer Randomize For i = 1 To 100 arr(i) = Int(Rnd * 10000) Print Format(arr(i), "@@@@ "); If i Mod 10 = 0 Then Print Next Print Print "最大值=...

Private Sub Command1_Click() Randomize (Timer) Dim a(1 To 100) a(1) = Int(Rnd * 9000 + 1000) Min = a(1) Print a(1); For i = 2 To 100 a(i) = Int(Rnd * 9000 + 1000) If a(i) < Min Then Min = a(i) Print a(i); If i Mod 10 = 0 Then P...

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 UB...

在你基础上,我加了几句代码就可以了: 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) +...

Private Sub Command1_Click() Me.Cls Dim arr(10) As Single, j As Long, m As Single, n As Single m = 0 n = 100 For j = 1 To 10 arr(j) = 60 + Format(Rnd() * 39, "0") + (Rnd() * 2 \ 2) * 0.5 + (Rnd() * 2 \ 2) * 0.5 If m = arr(j) T...

你是不是应该对最大值和最小值赋初值(比如把 r(1) 赋给最大值和最小值)呢?不然最小值默认初始值是‘0’,后面的判断就不起作用了。你可以加个断点试试,他们的初始值是多少。。。

Dim a(20) As Integer Randomize() For i = 0 To 20 a(i) = Int(Rnd() * 100) Next Dim b As New Collection b.Add(0) For i = 1 To 20 For j = 1 To b.Count If a(i) > a(b.Item(j)) Then b.Add(i, , j) GoTo tothis End If Next b.Add(i) tot...

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