VB编程求1-1000以内任意两数间的所有质数!
来源:学生作业帮 编辑:百度作业网作业帮 分类:综合作业 时间:2024/07/31 20:36:10
VB编程求1-1000以内任意两数间的所有质数!
就是要在窗体内任意输入两个自然数(均小于1000)显示这两个数之间所有质数.
就是要在窗体内任意输入两个自然数(均小于1000)显示这两个数之间所有质数.
![VB编程求1-1000以内任意两数间的所有质数!](/uploads/image/z/945823-31-3.jpg?t=VB%E7%BC%96%E7%A8%8B%E6%B1%821-1000%E4%BB%A5%E5%86%85%E4%BB%BB%E6%84%8F%E4%B8%A4%E6%95%B0%E9%97%B4%E7%9A%84%E6%89%80%E6%9C%89%E8%B4%A8%E6%95%B0%21)
Private Sub Command1_Click()
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim i As Integer,j As Integer
a = Text1
b = Text2
If a > b Then
c = a
a = b
b = c
End If
c = 0
For i = a To b
For j = 2 To i - 1
If i Mod j = 0 Then
Exit For
End If
Next j
If j = i Then Print i
Next i
End Su
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim i As Integer,j As Integer
a = Text1
b = Text2
If a > b Then
c = a
a = b
b = c
End If
c = 0
For i = a To b
For j = 2 To i - 1
If i Mod j = 0 Then
Exit For
End If
Next j
If j = i Then Print i
Next i
End Su