5.用随机函数产生20个[10,100 )的随机整数,求出随机数中的最大和最小值,并按照由

1个回答

  • 考试时把不要的注释去掉

    Private Sub Form_Click()

    Dim i,num(1 To 5) As Integer,smax As Integer,smin As Integer,savg As Single

    savg = 0

    Print "10-20范围内的5个随机数如下:"

    For i = 1 To 5

    num(i) = 10 + Int(11 * Rnd) '产生[10,20]区间的5个随机数

    If i = 1 Then smax = num(i):smin = num(i)

    If smax < num(i) Then smax = num(i) '求最大值

    If smin > num(i) Then smin = num(i) '求最小值

    savg = savg + num(i) '求平均值,最后结果要除以数目

    Print num(i);

    Next i

    savg = savg / 5

    Print

    Print "最大值"; smax,"最小值"; smin,"平均值"; savg

    End Su