求1-1000内的素数,把这些素数显示在窗体上,每行打印10个素数...
发布网友
发布时间:2024-10-10 03:59
我来回答
共1个回答
热心网友
时间:2024-10-31 02:44
Private Function IsPrimes(ByVal n As Long) As Boolean
For i = 2 To n - 1
If n Mod i = 0 Then Exit For '如果能被2 ~ N-1中任何一个数整除,则不是素数,跳出For循环
Next i
If i >= n Then '如果正常跳出For循环,则I跳出循环For后的值应该是N,所以满足这个条件
IsPrimes = True
End If
End Function
Private Sub Form_Load()
Me.Show
For i = 1 To 1000
If IsPrimes(i) = True Then
Print Format(i, "000") & " ";
x = x + 1
If x Mod 10 = 0 Then Print
End If
Next
End Sub