m = Text1.Text
For i= 1 To Len(m)
c= Mid(m,i, 1)
If c>= "0" And c<= "9" And i Mod 2 = 0 Then k=1 Else k= 2
a(k)= a(k)+ 1
Next i
数组a各元素的初始值都为0,文本框Text1上输入内容为“9+ ILM2019IT”(不包含双引号)。该程序段运行后,a(2)的值为( )
n = Val(Text1.Text)
For i=2 To n- 1
If n Mod i= 0 Then
a= False
End If
Next i
If Then Label1.Caption = "不是素数" Else Label1.Caption = "是素数"
程序段中有3处加框的地方需要完善代码,现有如下代码:
①Exit For
②a=True
③a = False
则程序段里从上往下方框里的代码分别是( )
n= 6
For i= 1 To 2
k=i
j=i+ 1
Do While j<= 3
If a(k) < a(j) Then k=j
j=j+ 1
Loop
If i<> k Then
t= a(i): a(i) = a(k): a(k)= t
End If
m=n-i+ 1
For j= m- 1 To 4 Step -1
If a(m)> a(j) Then m=j
Next j
If m<>n-i+ 1 Then
t= a(n-i+1):a(n-i+ 1)= a(m): a(m)= t
End If
t= a(i): a(i)= a(n-i+ 1):a(n-i+ 1)=t
Next i
数组元素a(1)到a(6)的初始值依次为“39,40,35,21,33,32”,运行程序后,a(4)的值是( )
i= 1:j= 6:key=8
Do While i<= j
m=(i+j)\2
If a(m)<key Then
j=m- 1
Else
i=m+ 1
End If
Loop
数组元素a(1)到a(6)的值依次为“9,8,8,8,7,6”,运行该程序段后,下列说法正确的是( )
图 a |
图 b |
图 c |
图 a |
图 b |
Private Sub Command1_ Click()
Dims As String, c As String, i As Integer
Dim sum As Single, sum1 As Single, sum2 As Single, k As Integer,j As Integer
s = Text1.Text : sum2=0:k= 1
For i= 1 To Len(s)
c=
If c= "*" Or c= "/" Then
If c="*" Then
sum = Val(Mid(s,i+ 1, 1)) * Val(Mid(s,i- I, 1))
Else
sum = Val(Mid(s, i- 1, 1))/ Val(Mid(s,i+ 1,1))
End If
j=i-2
Do While
c = Mid(s,j, 1)
If c="+" Then sum1 = Val(Mid(s,j-1, 1)) + sum
If c="-" Then sum1 = Val(Mid(s,j- 1, 1)) - sum
sum=sum1
j=j- 1
Loop
If k=1 Then
sum2 = sum2 + sum
Else
c= Mid(s, k, 1)
If c =“+" Then sum2 = sum2 + sum
If c="" Then sum2 = sum2 - sum
End If
k=
End If
sum=0
Next i
Label2.Caption = sum2
End Sub
Dim zh(1 To 16) As String,zrs As Integer
Dim xk(1 To 1000) As String '存放同学的选课科目组合,已知学生人数少于1000人
Dim zh2(1 To 35) As String '存放35种选课科目组合
Dim rstj(1 To 35) As Integer '存放各种选课组合选课人数
Private Sub Form_ Load( )
'本过程从数据库中读取学生的选课情况数据,存放在数组xk中,学生的总人数存放在变量zrs。
'代码略
End Sub
Private Sub Command1_ Click()
Dim iAs Integer, j As Integer, m As Integer, n As Integer, k As Integer
Dim km(1 To 7) As String
List1.Clear
List1.AddItem "序号"+ "" + "组合名称"
km(1) = "物": km(2) = "化": km(3)= "生": km(4)= "政"
km(5) = "史": km(6) = "地": km(7)= "技"
m= 1
For i= 1 To 5
For k=i+ 1 To 6
zh(m) = km(i) + km(k)
m=m+1
Next k
Next i
j=3:n= 1:y=j
For i= 1 To m
For k=y To 7
zh2(n)=
If n<= 9 Then
List1.AddItemn&""&" " & zh2(n)
Else
List1.AddItemn&" " & zh2(n)
End If
n=n+ 1
Next k
y=y+ 1
If y= 8 Then
j= : y=j
End If
Next i
End Sub
Private Sub Command2_ Click()
Dim i As Integer
List2.Clear
List2.Addltem "组合名称" +""+ "选课人数”
For i= 1 To 35
rstj(i)=
List2.AddItem zh2(i) +"" + Str(rsij(0)
Next i
End Sub
Function tj(zhme As String) As Integer '统计某种选课组合的选课人数
Dim i As Integer, rs As Integer
rs= 0
For i= 1 To zrs
If zhmc = xk(i) Then
rs=rs+ 1
End If
Next i
tj=rs
End Function