Jump to content
Sign in to follow this  


Recommended Posts


i created this function:

Func IsPrimeNumber($num)
   If IsNumber($num) = 0 Or $num = 0 Then
      Return -1
      Local $pnum = 0
      Local $npnum = 0
      $i = 2
      While $i < Int($num)
         $ch = $num / $i
         $i = $i + 1
         If $ch = Int($ch) Then
            $npnum = 1
            $pnum = 1
      If $num = 2 Then
         Return 1
      ElseIf $npnum = 1 And $num <> 2 Then
         Return 0
      ElseIf $pnum = 1 And $npnum = 0 Then
         Return 1

it checks if a number is a prime number. if it is, the function returns 1, if not it returns 0. if you insert a string or 0 (which is not a real number) it returns -1


$z = IsPrimeNumber(2)
If $z = 1 Then
   $y = "TRUE"
ElseIf $z = 0 Then
   $y = "FALSE"
ElseIf $z = -1 Then
   $y = "NO NUMBER"
MsgBox(0, "is prime?", $y)

this returns 1 and displays TRUE

but if i use it like this:

$log = @ScriptDir & "\Primzahlen.txt"

$op = FileOpen($log, 1)
For $i = 1 To 100
   If IsPrimeNumber($i) = 1 Then
      FileWriteLine($log, $i)

it doesnt write 2 in the log but as you know 2 returns 1 and is a prime number, too.

now my question: whereĀ“s the mistake? :idiot:


Edited by /\/\1|<3

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.