试题

试题 试卷

logo

题型:单选题 题类:常考题 难易度:困难

浙江省临安市昌化中学2019届高三上学期信息技术期末模拟试卷

【加试题】有如下VB程序段:

s = "adobe": ans = ""

For i = 1 To Len(s)

    A(i) = Mid(s, i, 1)

Next i

For i = 1 To Len(s)

       k = i

       For j = i To Len(s) Step 2

           If a(j) < a(k) Then k = j

       Next j

       If k <> i Then t = a(k): a(k) = a(i): a(i) = t

    Ans = ans + a(i)

Next i

label1.Caption = ans

该程序段运行后,标签Label1中显示的内容是(  )

A、adobe B、odeba C、abdeo D、abedo
举一反三
编写一个VB程序,实现程序功能如下:随机产生10个1~20之间的整数存放在数组a,在列表框List1中显示,单击“排序”按钮Command1后,在列表框List2中显示升序排序后的结果。具体算法描述如下:引入数组index,index(i)存储i位置应放置的数组元素的下标。排序完毕,a(index(i))成为升序序列,即a(index(1))≤a(index(2))≤a(index(3))≤……≤a(index(i))。在数组a的所有元素中找出最小元素,将其所在位罝存放在数组元素index(1)中,然后在余下的元素中找出最小元素,将其所在位置存放在数组元素index(2)中,以此类推,直到完成所有元素排序。如n=5时,数组a排序后各变量值如下表所示。

i

1

2

3

4

5

a(i)

17

19

9

13

6

index(i)

5

3

4

1

2

a(index(i))

6

9

13

17

19

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

Const n = 10

Const maxn = 20

Dim a(1 To n) As Integer, index(1 To n) As Integer, flag(1 To n) As Boolean

Private Sub Form_Load()

Dim i As Integer

Randomize

For i = 1 To n

 flag(i) = False

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

 List1.AddItem Str(a(i))

Next i

End Sub

Private Sub Command1_Click()

Dim i As Integer, j As Integer

Dim k As Integer

For i = 1 To n

 For j = 1 To n

  If flag(j) = False Then k = j: Exit For

 Next j

 For m = k + 1 To n

  If Then k = m     ‘⑴

 Next m

 index(i) = k

 flag(k) = True

Next i

For i = 1 To n

 List2.AddItem      ‘⑵

Next i

End sub

⑴{#blank#}1{#/blank#} ⑵{#blank#}2{#/blank#} 

返回首页

试题篮