A=1:b=1:n=12
f(1)=a:f(2)=b
For i=3 to n
c=a+b
f(i)=c Mod 4
a=b
b=c
Next i
执行该段程序后,数组元素f(12)的值为( )
当文本框Text1中输入的值为32时,程序运行结束后变量c的值为( )
(涨跌幅(%)=(本期价格(元)-上期价格(元))/上期价格(元)×100)
图2
⑴将n乘以3后加1产生一个新的数
⑵对产生的新数循环执行如下操作:新数是偶数时,用新数除以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
图1
图2
实现上述功能的VB程序如下,但划线部分代码有错,请改正。
Private Sub Command1_Click()
Dim x(1 To 100) As Single, y(1 To 100) As Single
Dim tmp As Single, length As Single, sum As Single, x1 As Single, y1 As Single
Dim i As Integer, j As Integer, k As Integer
Randomize
List1.Clear
k = Val(Text1.Text)
For i = 1 To k
x(i) = Int(Rnd * 90) / 10 + 1
y(i) = Int(Rnd * 90) / 10 + 1
List1.AddItem "X:" + Str(x(i)) + " " + "Y:" + Str(y(i))
Next i
For i = 1 To k - 1
For j = 1 To k - i
If x(j) > x(j + 1) Then
x(i)=x(i) + x(j)
x(j) = x(i) - x(j)
x(j) = x(i) + x(j) ‘①
tmp = y(j)
y(j) = y(j + 1)
y(j + 1) = tmp
End If
Next j
Next i
sum = 0: length = 0
For i = 1 To k - 1
x1 = (x(i) - x(1)) ^ 2 ‘②
'变量y1计算方法同x1,代码略
length = Sqr(x1 + y1)
sum = sum + length
Next i
Text2.Text = Str(Int(sum * 10) / 10)
End Sub
① ②
⑴找出文章(以“.”结束)中所有用英文表示的数字(均为小写,数字范围1≤n≤20),单词与数字对应如下:
⑵将这些数字平方后除以100取余,得到两位数如00,04,21,96。
⑶把这些两位数按升序排成一行,组成一个最小的新数,如果新数开头为0,就去除。
⑷步骤(3)找出的最小数即为密码。
小明按照上述方法,设计了一个解密的VB程序,功能如下:单击“解密”按钮Command1,程序依次将文本框Text1中以空格分隔的每个英文单词取出,若单词属于数字单词,则按解密步骤进行处理,最后在文本框Text2中输出解密结果。
程序运行效果如图所示,请回答下列问题:
Dim a(1 To 20) As String
Private Sub Form_Load()
a(1) = "one": a(2) = "two"
‘……将所有数字单词按顺序存入数组a中,代码略
End Sub
Private Sub Command1_Click()
Dim s As String, tmp As String
Dim c as Integer, i As Integer, j As Integer, k As Integer, t As String, ch As As String, code As Long
Dim b(1 To 100) As String ‘b数组存放数字单词处理后得到的两位数
s = Text1.Text
c = 0: i = 1: flag = True:t = ""
Do While i <= Len(s)
ch = Mid(s, i, 1)
If ch >= "a" And ch <= "z" Then
t = t + ch
flag = False
ElseIf flag = False Then
For j = 1 To 20
If t = a(j) Then
c = c + 1
b(c) =
End If
Next j
t = ""
flag = True
End If
i = i + 1
Loop
’将b数组中的两位数按数值大小进行升序排序,代码略
For i = 1 To c
t = Val(b(i))
Next i
Text2.Text = Str(code)
End Sub
Function decode(num As Integer) As String
Dim mo As Integer
mo = num * num Mod 100
If mo = 0 Then
decode = "00"
ElseIf Then
decode = "0" + Trim(Str(mo))
Else
decode = Trim(Str(mo)) 'Trim为去除字符串两端空格的函数
End If
End Function