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 这个就是的 上面的>改成

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

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

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

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 "最大值=...

代码及注释如下: 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() 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) +...

二楼有简便方法……此方法作为参照_(:зゝ∠)_ 写个函数丢模块里 题目描述有点不清楚,大致代码如下 使用方法:返回值=MaxNum(数组名称) 如:Dim a(1 to 5) as integer:b=MaxNum(a) Public Function MaxNum(sz() As Integer) As IntegerDim i As Inte...

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

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