VB数组问题,这个程序运行界面是放的什么标签?程序怎么写?

第二题。... 第二题。 展开
 我来答
keanelaun
推荐于2016-04-04 · TA获得超过167个赞
知道小有建树答主
回答量:148
采纳率:100%
帮助的人:103万
展开全部

不用放标签,一个picturebox,5个按钮

代码如下

Dim a%(1 To 10)
Private Sub Command1_Click()
Picture1.Print "产生的一维数组为:"
For i = 1 To 10
 a(i) = Int(Rnd * 90 + 10)
 Picture1.Print a(i);
Next i
Picture1.Print
End Sub

Private Sub Command2_Click()
Dim n%, m%
n = a(1)
m = 1
For i = 2 To 10
If a(i) > n Then n = a(i): m = i
Next i
Picture1.Print
Picture1.Print "第" & m & "个元素" & a(m) & "为最大值"
End Sub

Private Sub Command3_Click()
Dim aver#, sum#
For i = 1 To 10
sum = sum + a(i)
Next i
aver = sum / 10
Picture1.Print
Picture1.Print "产生的随机数的平均值为:" & aver
End Sub

Private Sub Command4_Click()
Dim t%
For i = 1 To 10
 For j = 1 To 9
  If a(j) > a(j + 1) Then
  t = a(j): a(j) = a(j + 1): a(j + 1) = t
  End If
 Next j
Next i
Picture1.Print
Picture1.Print "排序后的一维数组为:"
For i = 1 To 10
 Picture1.Print a(i);
Next i
Picture1.Print
End Sub

Private Sub Command5_Click()
Dim x%, y%, b%(1 To 11)
Picture1.Print
x = InputBox("请输入要插入的数")
For i = 1 To 10
 If a(i) > x Then
 y = i
 Exit For
 End If
Next i
For i = 1 To y - 1
b(i) = a(i)
Next i
b(y) = x
For i = y + 1 To 11
b(i) = a(i - 1)
Next i
Picture1.Print "插入后的一维数组为:"
For i = 1 To 11
 Picture1.Print b(i);
Next i
End Sub

Private Sub Form_Load()
Command1.Caption = "产生随机数"
Command2.Caption = "求最大值"
Command3.Caption = "求平均值"
Command4.Caption = "升序排序"
Command5.Caption = "插入新数据"
Form1.Caption = "数组应用实例"
End Sub

 

运行结果如下

推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式