题型:综合题 题类:常考题 难易度:普通
高中信息技术综合库——枚举算法3
Private Sub Command1_Click()
Dim i As Integer, n As Integer
Dim s As Integer, t As Integer, k As Integer
s = 0
For i = 1 To 1000
n = i
t = 0
k = 0
Do While n > 0
If n Mod 2 = 1 Then t = t + 1 Else k = k + 1
Loop
If Then s = s + 1
Next i
Text1.Text = Str(s)
End Sub
程序代码如下:
Private Sub Command1_Click()
Dim i As Integer
List1.Clear '清除列表框内容
For i = 3 To 97 ___①___ If f(i) And f(i+2)=true Then List1.AddItem Str(i) + " 和 " + Str(i + 2) End If Next i |
End Sub
Private Function f(x As Integer) As Boolean '判断是否为素数,若是返回true,若不是则返回false
………
End Function
试题篮