
Const MAXNUM = 100
Dim i As Integer, n As Integer
Dim a(1 To MAXNUM ^ 2) As Integer
Private Sub Command1_Click()
Dim line As String
n = Val(Text1.Text)
line = ""
List1.Clear
Randomize
For i = 1 To n ^ 2
a(i) = ①
If i > 1 And i Mod n = 1 Then
List1.AddItem line
line = Str(a(i))
Else
line = ②
End If
Next i
List1.AddItem line
End Sub
Private Sub Command2_Click()
Label1.Caption = ""
For i = 1 to ③
Label1.Caption = Label1.Caption & Str(a(i + (i - 1) * n))
Next i
End Sub
① ② ③
解密规则:将整数中各个位中的每一位值乘以5,然后除以8所得余数即为该位的值,然后将所得数的首末位进行交换。如数字9357,解密后的值为3715。

Private Sub Decryp_Click( )
Dim zs As Long, g As Integer
Dim b As Integer, q As Integer
Dim m As Integer, s As Integer
Dim jmh As String
zs = Val(Text1.Text)
For m = zs To
q = (m \ 1000) * 5 Mod 8
b = ((m \ 100) Mod 10) * 5 Mod 8
s = ((m \ 10) Mod 10) * 5 Mod 8
g = (m Mod 10) * 5 Mod 8
List1.AddItem Str(m) + " " + jmh
Next m
End Sub
|
|
图1 | 图2 |
Private Sub Command1_Click()
Const code = "0123456789ABCDEF"
Dim s1 As String, s As String '变量s存储转换后的结果
Dim x As Long, R As Integer
If R >= 2 And R <= 16 Then
x = Val(Text1.Text)
s = ""
Do While x > 0
y = x Mod R
x =
s1 = Mid(code, y + 1, 1) '将余数转换为对应的字符
s =
Loop
List1.AddItem "(" & Text1.Text & ")10" & " →(" & s & ")" & R
End If
End Sub
s=Text1.Text
List1.Clear
Len1=Len(s) ‘①
For i=l To len1 ‘②
For j=1 To len1-i ‘③
List1.Addltem Mid(S,j,i) ‘④
Next j
Next i
运行时发现未输出所有子串,则修改( )
解决该问题的VB程序段如下,在划线处填入正确的语句以实现功能。
Dim a(0 To 10) As Integer
Dim b(0 To 10) As Integer
n = 10
For i = 0 To 10
a(i) = 0
Next
a(1) = 1
b(1) = 1
For i = 1 To n
s = ″ ″
For j = 1 To
s = s + ″ ″'在s中加入一个空格
Next
For j = 1 To i
b(j) =
s = s + Str(b(j))
Next
Print s
For j = 1 To i
a(j) = b(j)
Next
Next
图a
图b
Private Sub Command1_Click()
Dim n As Integer, i As Integer, s As Integer, x As Integer, f As Boolean
n = Val(Text1.Text)
f = False: s = 0
i = 2
Do While f = False
x = 2
Do While x <= Int(Sqr(i)) And i Mod x <> 0
①
Loop
If x > Int(Sqr(i)) Then
s = s + 1
If ② Then
Label2.Caption = "第" & Str(n) & "个素数是:" & Str(i)
f = True
End If
End If
i = i + 1
Loop
End Sub
① ②
y=0
n=Len(Text 1.Text)
For i=1To n
c=Mid(Text 1.Text,i,1)
If c>=“0”And c<=“9”Then
x=Val(c) :a(x) =a(x) + 1
End If
Next i
For i= 0 To 9
If a(i) >0Then y=y+ 1
Next i
Label 1.Caption=Str(y)
a数组各元素的初值为0,程序运行时,在文本框Text 1中输入内容“pi=3.1415926535”,单击按钮Command 1后,标签Label 1中显示的内容是( )
实现上述功能的VB程序如下:
Dim a(1 To 8) As Integer
Dim n As Integer
Private Sub Form_Load()
'排序前的8个数据存储在数组a中,并在列表框List1中显示
'代码略
End Sub
Private Sub Command1_Click()
Dim i As Integer, j As Integer, k As Integer
Dim pos As Integer '变量pos存储指定数据的位置(即下标值)
Dim s As String '变量s存储pos变化情况
s = Text1.Text
pos = Val(Text1.Text)
For i = 1 To n - 1
For j = n To i + 1 Step -1
If a(j) < a(j - 1) Then
k = a(j - 1)
a(j)=a(j-1) '(2)改错
a(j) = k
'如果pos位置的数据参与交换,则更新pos值,记录pos变化情况
If pos = j Then
pos = j - 1
s = s + "→" + Str(pos)
ElseIf Then '填写代码
pos = j
s = s + "→" + Str(pos)
End If
End If
Next j
Next i
Label4.Caption = "位置变化情况:" + s
For i = 1 To n
List2.AddItem Str(a(i))
Next i
End Sub
Dim d(1 to 5)as integer, i as integer
Dim flag as Boolean, j as integer
‘给数组元素d(1)至d(5)赋初值为1,代码略
Randomize
For i=1 to 5
J = 1: flag = True
d(i) = int(Rnd*9)
Do while j< =i-1 and flag = True
d(i) = int(Rnd*5+1)
If d(i) = d(j) then i=i-1: flag = False
j = j+1
Loop
Next i
运行程序后,数组中的数据值可能是( )
a=1:b=2
If a>0 And a>b Then a=a+1
a=a+1
If a<>b Then
a=a+1
b=b+1
End If
a=a+b
Label1.Caption=Str(a)
程序运行后,标签Label1上显示的内容为。
|
脚长 |
21.5-22.0 |
22.0-22.5 |
22.5-23.0 |
23.0-23.5 |
23.5-24.0 |
24.0-24.5 |
24.5-25.0 |
25.0-25.5 |
|
码数 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
程序代码如下,请回答下面问题:
height=float(input('请输入身高(cm):'))
①
if 21.5<=long<=22.0:
num=0 # num 为区间标记号,从 0 开始递推 1
else:
num=7
size=[34,35,36,37,38,39,40,41]
②
print('根据您的身高,推断您鞋的码数为:',size_h)
① ②
J=1:N=0
Do While N<3
J=J*(J+1)
N=N+1
Loop
Print N; J
For i=1 To 2
For j=5 To i+1 Step-1
If a(j)<a(j-1) Then
t=a(j) : a(j)=a(j-1) : a(j- 1)=t
End If
Next j
Next i
数组元素a(1)到a(5)的值依次为“95,88,66,80,75”,经过该程序段“加工”后,数组元素a(1)到a(5)的值依次为( )



a=[]
csv_file=open("xuehao.csv", "r", encoding='utf-8')
flines=csv_file. readlines() #将文件中所有数据按行读入flines中
csv_file. close() #关闭文件
# 将每个数据行中的各项信息以“,”作为分隔符切割成字符串存入列表a中
for line in flines:
tmp=list(line. strip("\n"). split(","))
a. append(tmp)
n=len(a)
i=1; m=n-1 #变量m表示删除重复数据后的实际数据个数
while i<n:
for j in range(m, i, -1):
if :
tmp=a[j]; a[j]=a[j-1]; a[j-1]=tmp
elif a[j][4]==a[j-1][4]:
a[j]=a[m]
i+=1
for i in range (m+1):
print (a[i])