VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "动态数组"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   3900
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   3900
   StartUpPosition =   3  '窗口缺省
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Form_Click()        '        单击命令按钮运行该事件函数
  Dim mark() As Integer, i%, n%, aver
  n = InputBox("输入学生的人数")
  ReDim mark(1 To n)                    '声明存放n个学生成绩的数组
  aver = 0
  For i = 1 To n
    mark(i) = Int(Rnd * 101)            '通过随机数产生0～100的成绩
    aver = aver + mark(i)
  Next i
  ReDim Preserve mark(1 To n + 2)      '增加两个元素,存放平均分和高于平均分的人数,原来的学生成绩仍保留
  mark(n + 1) = aver / n
  mark(n + 2) = 0
  For i = 1 To n
    If mark(i) > mark(n + 1) Then mark(n + 2) = mark(n + 2) + 1
  Next i
  For i = 1 To n
    Print "mark("; i; ")="; mark(i)
  Next i
  Print "平均分="; mark(n + 1), "高于平均分人数="; mark(n + 2)
End Sub

