- Public Function Premier(n As Currency) As Boolean
- Dim x As Currency, y As Currency, r As Currency
- 'Définition d'un nombre premier
- 'Un nombre est premier s'il n'est divisible que par lui-même et par l'unité
- If n Mod 2 = 0 Then
- Premier = False
- Exit Function
- End If
-
- y = Abs(Fix(-Sqr(n)))
- If y < 3 Then y = 3
- For x = y To 3 Step -2
- If n Mod x = 0 And x <> n Then
- Premier = False
- Exit For
- Else
- Premier = True
- End If
- Next
- r = 0
- End Function
-
Public Function Premier(n As Currency) As Boolean
Dim x As Currency, y As Currency, r As Currency
'Définition d'un nombre premier
'Un nombre est premier s'il n'est divisible que par lui-même et par l'unité
If n Mod 2 = 0 Then
Premier = False
Exit Function
End If
y = Abs(Fix(-Sqr(n)))
If y < 3 Then y = 3
For x = y To 3 Step -2
If n Mod x = 0 And x <> n Then
Premier = False
Exit For
Else
Premier = True
End If
Next
r = 0
End Function