Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A different and better way to find prime numbers
#15
Here's a prime number generator that I created a couple of months ago:
[syntax="QBasic"]DEFLNG I, X
DEFINT P
CLS
INPUT "Enter a number: ", i
prime = 1
FOR x = FIX(SQR(i) + SGN(SQR(i)) * .5) TO 1 STEP -1
IF i > 1 THEN
IF (i MOD x = 0) AND (x <> 1) THEN
prime = 0
EXIT FOR
END IF
ELSE
prime = 0
EXIT FOR
END IF
NEXT
PRINT LTRIM$(STR$(i)) + " is ";
IF prime <> 1 THEN PRINT "not ";
PRINT "prime"[/syntax]
Don't question it, just enjoy it. :-P
974277320612072617420666C61696C21 (Hexadecimal for those who don't know)
Reply


Messages In This Thread
A different and better way to find prime numbers - by rpgfan3233 - 09-18-2005, 10:12 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)