Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fast Primes
#8
I also wrote a program to determine prime numbers and tested it up to 1,000,000. Is the result fast, slow or acceptable?

Code: (Select All)

Option _Explicit

Dim As Long eingabe, anzahlprim, anzahl
Dim As Long primzahl, zahlenbereich
Dim As Single zeitstart, zeitende

Screen _NewImage(800, 600, 32)

anzahl = 0

Print Tab(15); "Ausgabe aller Primzahlen bis zur Eingabe"
Print
Input "Alle Primzahlen ausgeben bis: ", eingabe

Timer On
zeitstart = Timer

anzahlprim = 0
For primzahl = 2 To eingabe Step 1
  zahlenbereich = 2
  Do While primzahl Mod zahlenbereich <> 0
    zahlenbereich = zahlenbereich + 1
  Loop
  If zahlenbereich = primzahl Then Print Using "#####"; primzahl;

  If zahlenbereich = primzahl Then anzahlprim = anzahlprim + 1
Next
zeitende = Timer

Print: Print
Print Using "Sekunden: ####.##### "; zeitende - zeitstart

Print
Print Using "Bis ###,##### gibt es ##,#### Primzahlen"; eingabe, anzahlprim

End

[Image: Primzahlen2024-05-29.jpg]
Reply


Messages In This Thread
Fast Primes - by SMcNeill - 05-16-2024, 08:13 AM
RE: Fast Primes - by SMcNeill - 05-16-2024, 11:56 AM
RE: Fast Primes - by Sprezzo - 05-16-2024, 01:01 PM
RE: Fast Primes - by SMcNeill - 05-16-2024, 01:32 PM
RE: Fast Primes - by SMcNeill - 05-16-2024, 03:33 PM
RE: Fast Primes - by PhilOfPerth - 05-16-2024, 11:26 PM
RE: Fast Primes - by Kernelpanic - 05-29-2024, 05:53 PM
RE: Fast Primes - by Kernelpanic - 05-29-2024, 06:03 PM
RE: Fast Primes - by SMcNeill - 05-30-2024, 12:03 PM
RE: Fast Primes - by Pete - 05-30-2024, 06:33 AM
RE: Fast Primes - by Kernelpanic - 05-30-2024, 11:51 AM
RE: Fast Primes - by Kernelpanic - 05-30-2024, 12:11 PM
RE: Fast Primes - by SMcNeill - 05-30-2024, 12:21 PM
RE: Fast Primes - by Kernelpanic - 05-30-2024, 12:55 PM
RE: Fast Primes - by SMcNeill - 05-31-2024, 03:55 AM
RE: Fast Primes - by Kernelpanic - 06-03-2024, 08:58 PM
RE: Fast Primes - by SMcNeill - 06-03-2024, 10:45 PM
RE: Fast Primes - by Kernelpanic - 06-03-2024, 11:38 PM
RE: Fast Primes - by eoredson - 06-06-2024, 04:44 AM



Users browsing this thread: 11 Guest(s)