题库 高中信息

题干

素数:只能被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
上一题 下一题 0.99难度 填空题 更新时间:2015-08-20 07:55:57

答案(点此获取答案解析)