收藏的幾個求1-100內素數的方法…
不知道這個VB的代碼在語法高亮插件裡應該用什麼語言表示。。。
1.
Private Sub Form_Click()
Dim i, j As Integer
For i = 1 To 100
For j = 2 To Sqr(i)
If i Mod j = 0 Then
Exit For
End If
Next j
If j >= Sqr(i) Then
Print i
End If
Next i
End Sub
2.
Private Sub Form_Click()
Dim i, j, b As Integer
For i = 2 To 100
For j = 2 To i - 1
If i Mod j = 0 Then Exit For
Next j
If j > i - 1 Then Print i & " ";
Next
End Sub
3.
Private Sub Form_Click()
Dim flag As Boolean, i As Integer
For i = 2 To 100
flag = True
For j = 2 To Sqr(i)
If i Mod j = 0 Then flag = False
Next
If flag Then Print i & " ";
Next
End Sub