/\/\1|<3 Posted December 26, 2004 Posted December 26, 2004 (edited) i created this function: Func IsPrimeNumber($num) If IsNumber($num) = 0 Or $num = 0 Then Return -1 Else 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 Else $pnum = 1 EndIf WEnd If $num = 2 Then Return 1 ElseIf $npnum = 1 And $num <> 2 Then Return 0 ElseIf $pnum = 1 And $npnum = 0 Then Return 1 EndIf EndIf EndFunc 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 example: $z = IsPrimeNumber(2) If $z = 1 Then $y = "TRUE" ElseIf $z = 0 Then $y = "FALSE" ElseIf $z = -1 Then $y = "NO NUMBER" EndIf 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) EndIf Next FileClose($op) 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? Mike Edited December 26, 2004 by /\/\1|<3
/\/\1|<3 Posted December 26, 2004 Author Posted December 26, 2004 (edited) works nowcorrect functionMike Edited December 26, 2004 by /\/\1|<3
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now