1. 下列VB程序的功能是:程序运行时,单击按钮Command1随机产生20个范围在1-1000(包括1和100)的整数,并在列表框List1中显示,然后单击按钮Command2,计算随机产生的20个整数中的最大值、最小值和平均值,并分别在Text1、Text2和Text3中显示,程序的运行界面如图所示。请在划线上填入合适的代码:

Const n = 20

Dim a(1 To n) As Integer

Private Sub Command1_Click()

Dim i As Integer

Randomize

For i = 1 To n

  a(i) = Int(Rnd * 1000) + 1

  List1.AddItem Str(a(i))

Next i

End Sub

Private Sub Command2_Click()

Dim i As Integer, max As Integer

Dim min As Integer, sum As Single

max = a(1): min = a(1)

sum = 0

For i = 2 To n

  If Then max = a(i)

  If a(i) < min Then min = a(i)

  sum = sum + a(i)

Next i

Text1.Text = Str(max)

Text2.Text = Str(min)

Text3.Text = Str(sum)

End Sub

【考点】
程序的调试及运行;
【答案】

您现在未登录,无法查看试题答案与解析。 登录
综合题 普通
能力提升
变式训练
拓展培优
换一批