09-14-2005, 04:54 AM
Why use the Sieve of Eratosthenes for finding prime numbers? There is a better, shorter, and faster way, and I figured it out on my own. Here is the code:
INPUT "Number: " , n
FOR I = 2 TO n - 1
IF n MOD I = 0 THEN PRINT "Number not prime.": END
NEXT
PRINT 'Number prime."
In case youre wondering how this works, the MOD command just returns the remainder from division. If a number is prime, then it will return all remainders, since it will not go into any number evenly. However, if it does return a remander, then it is not prime, since it is divisible by a number other than itself and 1.
Enjoy, I guess...
INPUT "Number: " , n
FOR I = 2 TO n - 1
IF n MOD I = 0 THEN PRINT "Number not prime.": END
NEXT
PRINT 'Number prime."
In case youre wondering how this works, the MOD command just returns the remainder from division. If a number is prime, then it will return all remainders, since it will not go into any number evenly. However, if it does return a remander, then it is not prime, since it is divisible by a number other than itself and 1.
Enjoy, I guess...
quote="Bruce Raeman"]Anatomy (n): something everyone has, but which looks better on a girl[/quote]