题型:综合题 题类:常考题 难易度:普通
高中信息技术综合库——枚举算法3
①密码是六位数字,前面两位为59;②最后两位数字相同;③能被12和38整除。
程序界面如图1所示,单击 “帮助找回密码”按钮(Command1)后,可能的密码显示在列表框List1中。
Private Sub Command1_click( )
Dim x As Integer, s As Long
Dim y As Integer, i As Integer
For i = 0 To 9999
s = 590000 + i
If Then
x= s mod 10
y =
If x = y Then
List1.AddItem Str(s)
End If
End If
Next i
End Sub
图1
图2
程序代码如下:
Private Sub Command1_Click()
Dim i As Integer
List1.Clear '清除列表框内容
For i = 3 To 97 ___①___ If f(i) And ② Then List1.AddItem Str(i) + " 和 " + Str(i + 2) End If Next i |
End Sub
Private Function f(x As Integer) As Boolean '自定义函数f,返回值为逻辑型
Dim j As Integer
f = True
For j = 2 To Int(Sqr(x))
If x Mod j = 0 Then
f = ③ '函数返回值
Exit For '跳出For循环
End If
Next j
End Function
试题篮