试题

试题 试卷

logo

题型:综合题 题类:常考题 难易度:普通

浙江省杭州市西湖高级中学2018-2019学年高二下学期信息技术4月月考试卷

下列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

举一反三
返回首页

试题篮