Advertisement
946ben

Primzahlenrechner

Nov 16th, 2012
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 0.82 KB | None | 0 0
  1. $num = 0
  2. $from = $CmdLine[1]
  3. $to = $CmdLine[2]
  4. $from = Round($from, 0)
  5. $to = Round($to, 0)
  6. $full = "Primzahlen von " & $from & " bis " & $to & @CRLF
  7. if $from = 1 then $from = 2
  8. if $to < $from then
  9.    MsgBox(0, "Ähm...", "Von " & $from & " bis " & $to & "?" & @CRLF & "Wie soll das denn gehen?")
  10.    Exit
  11. EndIf
  12. $timer = TimerInit()
  13. for $i = $from To $to
  14.    $prim = 1
  15.    for $u = 2 To $i-1
  16.       $float = $i/$u
  17.       if Round($float, 0) = $float then
  18.          $prim = 0
  19.          ExitLoop
  20.       EndIf
  21.    Next
  22.    if $prim = 1 then
  23.       ConsoleWrite("Primzahl: " & $i & @CRLF)
  24.       $num = $num + 1
  25.       $full = $full & $i & @CRLF
  26.    EndIf
  27. Next
  28. FileDelete(@ScriptDir & "\prim.txt")
  29. $full = $full & @CRLF & @CRLF & $num & " Primzahlen in " & Round(TimerDiff($timer)/1000, 3) & " Sekunden gefunden"
  30. FileWrite(@ScriptDir & "\prim.txt", $full)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement