For i=1 To n-1
For j=n To i+l Step-1
If a(j)< a(j-1)Then
k=a(j):a(j)=a(j-1):a(j-1)=k
End If
Next j
Next i
For i=1 To 6
j=7
Do While i>i
If a(j)>a(j-1) Then
a(j)= a(j)+a(-1):a(j-1)=a(j)-a(j-1):a(j)=a(j)-a(j-1)
End If
j=j-1
Loop
Next i
For i=3 To 6
s=s+a(i)
Next i
Labell. Caption=Str(s)
已知数组元素a(1)到a(7)的值依次为“8,2,3,7,10,6,5”,则执行该程序段后,标签 Label1中显示的是( )
Dim i As Integer, Sum As Integer
Dim a(1 To 11) As Integer
Sum = 6
a(11) = 49
For i = 10 To 1 Step -1
a(i) = a(i + 1) - 1
If a(i) Mod 3 = 0 Then Sum = Sum + a(i)
Next i
Text1.Text = Str(Sum)
该程序段运行后,文本框text1中显示的内容是( )
n=6:Text2. Text=" "
m=Val(Text1. Text)
For i=1 To 3
k=i
j=i+1
Do While j<=m
If a(k)> a(j) then k=j
j=j+1
Loop
If i<>k Then
Text2. Text= Str(a(k))+Text2. Text
t=a(i):a(i)=a(k):a(k)=t
End If
Next i
数组元素d(1)到d(6)的值依次为“39,25,18,20,73,70”,现运行程序在文本框Text1里输入5,点击按钮Command1后文本框Text2中显示的内容是( )
(提示:SUMPRODUCT函数返回相应的数组或区域乘积的和。例如:= SUMPRODUCT((C4:C11="高等数学")*(D4:D11))表示在数据区域D4:D11中统计科目是高等数学的数值总和)
1)将n乘以3后加1产生一个新的数
2)对产生的新数循环执行如下操作:新数是偶数时,用新数除以2;新数是奇数时,用新数乘以3后加1
譬如,以2为初始值,则计算过程如下。2→7→22→11→34→17→52→26→13→40→20→ 10→5→16→8→4→2。数字2不能在10步之内回到初始值。
界面如图所示,回答下列问题:
Private Sub Command1_Click()
Dim n As Integer, t as Integer ,m as Integer ,s as String
t = n * 3 + 1
m = 1
s = ""
Do While
s = s + Str(t)
If t Mod 2 = 0 Then
t = t \ 2
Else
t = t * 3 + 1
End If
m = m + 1
Loop
If n = t Then
Label1.Caption = s + Str(n)
Else
Label1.Caption = "该数10步之内无法实现!"
End If
End Sub
程序运行时,在文本框Text1中输入共有礼物数n,单击“读取数据”按钮Command1,将从数据库gift. accdb中读取n个礼物的信息存储在相应的数组中,并显示在列表框List1中;在文本框Text2中输入轮到你拿礼物的序号(即第几个拿),单击“计算”按钮 Command2,则在列表框List2显示你获得的礼物信息,并在列表框list2最后一行显示获得的礼物总数。程序运行界面如图所示。
实现上述功能的VB程序代码如下,请回答下列问题:
Dim conn as New ADODB.Connection
Dim rs as New ADODB.Recordset
Dim bh(1 To 100) As string '数组bh存储礼物的编号
Dim x(1 To 100) As Single,y(1 To 100) As single '数组x、y分别存储礼物的横坐标和纵坐标
Dim dist(1 To 100) As single '数组dist存储礼物到原点的距离
Dim n As Integer '变量n表示礼物数
Private Sub Command1_Click()
Dim i As Integer
'从数据库中读取n件礼物的编号、横坐标、纵坐标,并存储在相应的数组中'代码略,下面代码的功能是计算各礼物到原点的距离
For i=1 To n
dist(i)= ①
List1. AddItem bh(i)+""+Str(x(i))+""+Str(y (i))+""+Str(dist(i))
Next i
End Sub
Private Sub Command2_Click()
Dim xh As Integer, i As Integer, j As Integer, k As Integer
Dim templ As String, temp2 As Single, p As Single, s As Single
xh=Val(Text2. Text)
'将礼物按到原点的距离从小到大排序,代码略
i=0: j=1: s=0
Do While (i< xh) And (j<=n)
If dist(j)<>s Then
②
i=i+1
End if
j=j+1
Loop
u=0
j=j-1
Do While ③
List2. AddItem bh(j)+Str(x(j))+Str(y(j))+Str(dist(j))
u=u+1
j=j+1
Loop
List2. AddItem"total:"+Str(u)
End sub
① ② ③