当前位置: 高中信息技术 / 填空题
  • 1. (2019高一上·嘉善月考) 编写一个VB程序,功能如下:随机产生100个0到99之间的整数,在列表框list1中显示,单击“统计”按钮Command1,统计落入各范围的整数个数,在列表框List2中按从高到低的顺序显示各范围的整数个数。程序运行界面如图所示。

    实现上述功能的VB程序如下,但加框处代码有错,请改正。

    Const n = 100

    Dim a(1 To n)As Integer

    Private Sub Form_Load( )

        ‘随机产生100个0到99之间的整数存数组a中,并在列表框list1中显示。

    End Sub

    Private Sub Command1_Click( )

        Dim i As Integer, j As Integer, t As Integer

        Dim b(0 To 9)As Integer, c(0 To 9)As Integer

        For i = 1 To n

               ①

        Next i

        For i = 0 To 9

            b(i) = i

        Next i

        i = 0

        Do While i <= 8

            For j = i + 1 To 9

                If  Then   ②

                    t = b(i): b(i) = b(j): b(j) = t

                    t = c(i): c(i) = c(j): c(j) = t

                End If

            Next j

            i = i + 1

        Loop

        List2.AddItem “范围元素个数”

        For i = 0 To 9

            List2.AddItem Str(b(i) * 10) + "~" + Str(b(i) * 10 + 9) + ": " + Str(c(i)) + "个"

        Next i

    End Sub

微信扫码预览、分享更方便