Option Explicit
Private Sub Form_click()"視窗單擊事件
Dim i As Integer
For i = 100 To 300 "生成100到300的所有數值
If isPrime(i) = 0 Then Print i "呼叫素數判斷函式判斷當前數是否為素數
Next i
End Sub
Function isPrime(X As Integer) As Integer
If X <= 1 Then isPrime = -1 "素數範圍>=2
For i = 2 To X - 1
If X Mod i = 0 Then
isPrime = 1 "合數
Exit For
Else
isPrime = 0 "素數
End If
End Function
Option Explicit
Private Sub Form_click()"視窗單擊事件
Dim i As Integer
For i = 100 To 300 "生成100到300的所有數值
If isPrime(i) = 0 Then Print i "呼叫素數判斷函式判斷當前數是否為素數
Next i
End Sub
Function isPrime(X As Integer) As Integer
Dim i As Integer
If X <= 1 Then isPrime = -1 "素數範圍>=2
For i = 2 To X - 1
If X Mod i = 0 Then
isPrime = 1 "合數
Exit For
Else
isPrime = 0 "素數
End If
Next i
End Function