vb 键盘输入10个数 用子过程求10个数的最大值 平均值 排序 窗体单击事件调用这些函数

如题所述

第1个回答  2011-05-10
Private Sub Form_click()
Dim a(1 To 10)
For i = 1 To 10
a(i) = Val(InputBox("a(" & i & ")"))
Print a(i);
Next i
Print

Call px(a)
For i = 1 To 10
Print a(i);
Next i
Print
Print "max=", max(a)
Print "min=", min(a)
End Sub
Function max(a())
max = a(LBound(a))
For i = LBound(a) + 1 To UBound(a)
If max < a(i) Then max = a(i)
Next i
End Function
Function min(a())
min = a(LBound(a))
For i = LBound(a) + 1 To UBound(a)
If min > a(i) Then min = a(i)
Next i
End Function
Sub px(a())
For i = LBound(a) To UBound(a) - 1
For j = UBound(a) To i + 1 Step -1
If a(i) > a(j) Then b = a(i): a(i) = a(j): a(j) = b
Next j, i
End Sub本回答被提问者和网友采纳

vb 键盘输入10个数 用子过程求10个数的最大值 平均值 排序 窗体单击事件...
Private Sub Form_click()Dim a(1 To 10)For i = 1 To 10 a(i) = Val(InputBox("a(" & i & ")"))Print a(i);Next i Print Call px(a)For i = 1 To 10 Print a(i);Next i Print Print "max=", max(a)Print "min=", min(a)End Sub Function max(a())max = a...

用VB语言随机输入10个数,输出最大值和最小值,和其位置
Next For i = 1 To 10 temp = temp & a(i) & " "Next temp = "这十个数是:" & temp & "最大数" & max & "的位置在" & maxi & " " & "最小数" & min & "的位置在" & minj MsgBox temp End Sub

怎么用vb计算10个任意数的平均值
要计算10个任意数的平均值,首先需要随机生成这10个数。这里我们设定这10个数在0到100之间。初始化最大值max为0,最小值min为100。接着,通过一个for循环进行10次迭代。在每次迭代中,调用randomize函数来初始化随机数生成器。随后,使用int函数结合rnd函数生成一个0到99之间的整数n,这个n即是当前的...

vb 编写一个程序,输入任意10个数字,从中找出最大和最小的数,并给出最...
ReDim SerAim(i)If Vimt(i) > Vimt(j) Then '这个语句是以小到大排序,数组的第一个就是最小数 If Vimt(i) < Vimt(j) Then '这个语句是以大到小排序,数组的第一个就是最大数 '注意上面的二个语句只能用一个!!Num = Vimt(i)Vimt(i) = Vimt(j)Vimt(j) = Num E...

vb随机生成10个数并显示在一个文本框中, 并找出最大数,指出它的位置
添加一个text1,输入以下代码,然后运行。单击窗体,十个随机数显示在text1中,弹出对话框,提示第几个为最大数,并将最大数选中。Private Sub form_Click()Dim a(1 To 10) As Integer, i As Integer Randomize For i = 1 To 10 a(i) = Int(Rnd * 90) + 10 Text1.Text = Text1....

用VB编写“任意输入10个数,将它们由大到小进行排序输出到窗体上”的...
Dim arr(10) As Long Private Sub Text1_KeyPress(KeyAscii As Integer)If KeyAscii <> 13 Then Exit Sub i = i + 1 Me.Caption = "输入第 " + CStr(i + 1) + " 个数"If i < 10 Then arr(i + 1) = Int(Text1.Text)Else i = 0 For x = 1 To 10 For y = 2 To x...

VB中输入10个数并按要求进行升序排序和降序的程序
如果需要自己输入数字,可以这样:'如果要自己输入数字,可以修改下面的代码Text1.Text = "": Text2.Text = "": Text3.Text = ""Text1.Text = "系统自动生成的十个数:" & vbCrLfFor I = 1 To 10AA(I) = 0: ZGCJ(I) = 0: ZDCJ(I) = 0RandomizeAA(I) = Int(Rnd * 90 + ...

...到100随机整数,并求出这10个数的最大值,最小值和平均数
dim Sum_num as int dim Arr_num(9) as int '赋予初始值 Min_num=101 Max_num=-1 Sum_num=0 '循环10次获得10个随机数 for i=1 to 10 randomize Arr_num(i-1)=int(rnd*100)+1 '判断后赋值最小值 if Arr_num(i-1)<Min_num then Min_num=Arr_num(i-1)'判断后赋值最大值 i...

用vb写跪求十个数的比较大小,从小到大排序,
for i=1 to N-1 for j=i to N if a[j]

vb编程:随机产生10个两位随机奇数,求其中的最大值、最小值和平均值
j = Int(Rnd * 100) + 10 Loop a(i) = j Next i Label1.Caption = "这10个数为:"For i = 0 To 9 Label1.Caption = Label1.Caption & a(i) & " "Next i j = a(0) '求最大数 For i = 1 To 9 j = IIf(j > a(i), j, a(i))Next i Label2.Caption = ...

相似回答