Dim s As String, i As Integer, n As Integer
Dim ch As String, ans As Integer
s= Text1.Text
n Len(s): ans=0
For i=1 To n
ch =Mid (s, i, 1)
ans =ans *2+ Val(ch)
Next i
Text2 Text ans
若程序运行后Tex2中显示的是“38”,则Text中输入的是( )
s=Text.Text
c=0
For i=1 To 26
⑴
Next
For i=1 To Len(s)
⑵
IF d(t)=0 Then d(t)=i
⑶
Next
Text2 Text=Str(c)
填空处的代码可由以下部分组成
①d(i)=0 ②=val(Mid(si, 1) ③IFd(t)<>0Andi-d(t)> c Then c=i-d(t)
④d(i)=1 ⑤t=Asc(Mid(s, i, 1)-Asc("a")+1 ⑥fi-d(t)> c Then c=i-d(t)
代码顺序正确的是( )
Dim a(1 To 100)As Integer, b(1 To 10) As Intege
Dim i As Integer, s As Integer, c As Integer
For i=1 To 100
a(i)=0
Next i
For i=1 To 9 Step 2
a(b(i))=a(b(i))+1: a(b(i+1)+1)=a(b(i+1)+1)-1
Next i
c=0
For i=1 To 100
c=c+a(i)
If c=0 Then s=s+ 1
Next i
Text1. Text= Str(s)
若数组b中的值依次为“5,10,7,20,30,40,40,60,55,70”,则程序运行后Text中的内容是( )
i=1: j=8: n=1
k=Val(Text1. Text)
Do While i<=j
m=(i+j)2
IF k<d(m) Then j=m-1 Else i=m+1
n=n+1
Loop
数组元素d(1)到d(8)依次为3,9,14,17,25,29,32,35,在文本框 Text1输人“14”。执行程序后,下列说法不正确的是( )
Private Sub Command2_Click()
Dim i As Integer, j As Integer, tmp As Integer
Dim s1 As String, t As Integer, s2 As String
t=1
For i=1 To n-2
For j= To n Step 2 ‘改错
If a(i)*t>a(j)*t Then
tmp =a(i): a(i)= a(j): a(j)=tmp
End if
Next j
‘填空①
Next i
For i =1 To n
If Then ‘填空②
s1 =s1 Str(a(i))
Else
s2=s2+Str(a(i))
End If
Text2. Text=“奇数位:”+s1
Text3. Text=“偶数位:”+s2
End Sub
回答以下问题:
奇数阶幻方的构造是所有幻方中最简单的,可以按照如下规则来实现:
⑴将1放在第一行中间一列;(如图2)
⑵从2开始直到n*n为止,各数按下列规则存放:
假设当前要存放的数为k,则k存放在k-1)数的右上方并按照规则
①若(k-1)放在第1行且不是最后一列,则将k存放在n行,(k-1)所在列右侧;(如图3)
②若(k-1)放在第n列且不是第一行,则将k存放在第1列,k-1)的上1行;(如图4)
③若(k-1)即不在第1行也不在最后1列:
若(k-1)右上方有数,则将k放在(k-1)的下1行的同一列。(如图5)
若(k-1)右上方没有数,则将k放在(k-1)的右上方;(如图6)
④若(k-1)在第1行第n列,将k填在(k-1)的正下方(如图7)
Private Sub Command1_Click()
Dim i As Integer, i As Integer, n As Integer ‘i表示行,j表示列
Dim a(1 To 1000) As Integer, k As Integer ‘数组a依次保存幻方中的数
Dim s As String
n= Val(Text1.Text)
j= ① : a(j)=1
i=1
For k =2 To n*n
If i=1 And j<>n Then
i=n: j=j+1
a((i-1)*n+j)=k
ElseIf j= n And i<> 1Then
② : j=1
a((i-1)*n+j)=k
ElseIf i=1 And j=n Then
i+1 =1
a((i-1)*n+j)=k
ElseIf i <> 1 And j<> n Then
If ③ Then
i=i-1:j=j+1
va((i-1)*n+j)=k
Else
i=i+1
a((i-1)*n+j)=k
End If
End If
Next k
List1. Clear
For i=1 To n
s=“”
For j=1 To n
s=s+ format(a((i-1)*n+j))
Next j
List1AddItem s
Next i
End Sub
Function format( x As Integer) As String ‘将数字字符串格式化为3个字符长度
Dim n As integer, i As Integer
format =Str(x)
n=Len(format)
For i=1 To ④
format ="”+ format
Next i
End Function
① ② ③ ④