什么是质数?
质数是指在大于1的自然数中,除了1和它本身以外不再有其他因数的自然数。
使用双循环和mod 对数值进行筛选找到1到100以内的质数
代码如下:
Dim i As Integer
Dim j As Integer
Dim bl As Boolean
For i = 2 To 100
bl = False
For j = i - 1 To 2 Step -1
If i Mod j = 0 Then
bl = True
Exit For
End If
Next j
If bl = False Then Me.Text2 = Me.Text2 & i & " ,"
Next i
附 件:
点击下载此附件
图 示: