Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SUB PBMAIN ()
- DIM strInput AS STRING
- DIM yorn AS STRING
- DIM n AS LONG
- DIM m AS LONG
- DIM lim AS LONG
- DIM s AS LONG
- DIM startTime AS DOUBLE
- DIM endTime AS DOUBLE
- DIM nums() AS BYTE
- PRINT "This program will calculate primes using a simple algorithm."
- INPUT "Enter limit for this search (enter for default): ", strInput
- IF strInput = "" THEN strInput = "100000000"
- lim = VAL(strInput)
- s = SQR(lim)
- startTime = TIMER
- REDIM nums(lim)
- FOR n = 2 TO s
- IF nums(n) = 0 THEN
- m = n * n
- WHILE m <= lim
- nums(m) = 1
- m += n
- WEND
- END IF
- NEXT
- endTime = TIMER
- PRINT "It took " + STR$(endTime - startTime) + " seconds to complete."
- INPUT "Would you like to display results (Y/N)? ", yorn
- PRINT ""
- IF yorn = "Y" OR yorn = "y" THEN PRINT "The primes up to " + STR$(lim) + " are:"
- m = 0
- FOR n = 2 TO lim
- IF nums(n) = 0 THEN
- IF yorn = "Y" OR yorn = "y" THEN PRINT STR$(n)
- m += 1
- END IF
- NEXT
- PRINT "Total primes count = " + STR$(m)
- PRINT "Press any key to exit. . . ";
- GETKEY
- END SUB
- PBMAIN
- ' ==================================================================================================
- ' OLD POWERBASIC VERSION
- ' DELETE AFTER THIS LINE IF NOT USING
- #COMPILE EXE
- #OPTIMIZE CODE ON
- #OPTIMIZE SPEED
- #DIM ALL
- FUNCTION PBMAIN () AS LONG
- DIM strInput AS STRING
- DIM yorn AS STRING
- DIM n AS LONG
- DIM m AS LONG
- DIM lim AS LONG
- DIM s AS LONG
- DIM startTime AS DOUBLE
- DIM endTime AS DOUBLE
- DIM nums() AS BYTE
- PRINT "This program will calculate primes using a simple algorithm."
- INPUT "Enter limit for this search (enter for default): ", strInput
- IF strInput = "" THEN strInput = "100000000"
- lim = VAL(strInput)
- s = SQR(lim)
- startTime = TIMER
- REDIM nums(lim)
- FOR n = 2 TO s
- IF nums(n) = 0 THEN
- m = n * n
- WHILE m <= lim
- nums(m) = 1
- m += n
- WEND
- END IF
- NEXT
- endTime = TIMER
- PRINT "It took" + STR$(endTime - startTime) + " seconds to complete."
- INPUT "Would you like to display results (Y/N)? ", yorn
- PRINT ""
- IF yorn = "Y" OR yorn = "y" THEN PRINT "The primes up to" + STR$(lim) + " are:"
- m = 0
- FOR n = 2 TO lim
- IF nums(n) = 0 THEN
- IF yorn = "Y" OR yorn = "y" THEN PRINT STR$(n)
- m += 1
- END IF
- NEXT
- PRINT "Total primes count =" + STR$(m)
- PRINT "Press any key to exit. . . ";
- WAITKEY$
- END FUNCTION
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement