题型:综合题 题类:常考题 难易度:普通
【bj】高中信息技术综合库——枚举算法及程序实现1
实现上述功能的VB代码如下。
Dim a(1 To 50) As Integer
Private sub Command1_Click()
Dim i As Integer
k=0: i=3
Do While i<= 100
If Not prime(i) Then
k=k+1
End If
i=i+2
Loop
For i=2 To k
If Then
List1 AddItem Str(a(i-1))+"和"+ Str(a(i))
End if
Next i
End Sub
Function prime (x As Integer)As Boolean
prime=False
For i=2 To Int(sar(x))
If x Mod i=0 Then
prime=True
Exit for
End If
Next i
End Function
试题篮