素数:只能被1和它本身整除的自然数。要求编写VB程序找出任意两个整数之间中所有的素数及个数,程序运行界面如下图所示。
请根据算法将下列程序补充完整。
Function prime(a As Integer) As Boolean
Dim j As Integer
prime = True
j = 2
Do While prime And j <=" a" \ 2
If a Mod j =" 0" Then
prime = False
Exit Do
End If
①
Loop
End Function
Private Sub Command1_Click( )
Dim i As Integer, a As Integer, b As Integer
Dim count As Integer
a = Val(Text1.Text)
b = Val(Text2.Text)
For i =" a" To b
If ② =" True" Then
List1.AddItem Str(i)
count =" count" + 1
End If
Next i
Label1.Caption = "素数共有" + Str(count) + "个!"
End Sub
相关知识点
推荐试卷