组卷题库 > 高中信息技术试卷库
试题详情
只能被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

知识点
参考答案
采纳过本试题的试卷
教育网站链接