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

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

很简单 for i=0 to 5 a(i)=inputbox("输入任意数",找最值) next i max=a(0) max_j=0 for j=1 to 5 if(a(j)>max) then max=a(j) max_j=j endif next j print max max_j 这个就是的 上面的>改成

1、遍历数组进行比较查找即可。 2、vb6示例代码: Option Explicit Private Sub Command1_Click() Randomize Timer Dim a(9) As Integer, i As Integer Dim x, Fp As Integer, Zp As Integer For i = 0 To 9 '模拟生成一个随机数组 a(i) = 50 - ...

代码及注释如下: 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大于...

代码及注释如下: 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大于...

查找数组中的最大值、最小值 及其位置 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 d() As Integer Dim i As Integer Dim MyMax As Integer Dim n As Integer n = Val(InputBox("输入n!")) ReDim d(n) As Integer For i = 1 To n d(i) = Val(InputBox("输入第" & i & "个数!")) Next i MyMax = d(1) For i = 2 To n If d(i)...

dim a(19) as integer, imax as integer, imin as integer, i as integer imax=49 imin=101 for i=0 to 19 a(i)=int(rnd*51)+50 if imaxa(i) then imin=a(i) print a(i), next print print "最大值和最小值的平均值是:";(imax+imin)/2

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

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

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

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