I wrote this prime number finder. for some odd reason, it only works for even numbers, and not odd ones that I know aren't prime.

I wrote this prime number finder. for some odd reason, it only works for even numbers, and not odd ones that I know aren't prime.
what is it I'm missing?
http://pastebin.com/HvXunX8f

Comments

  1. even... odd... you get the idea... english is not my first language, I can/will make mistakes from time to time, my bad!

    ReplyDelete
  2. btw, have found a very old basic program that does prime analysis on any given integer. too lazy to convert it to pascal, so will just post it here:
    10 rem prime analysis
    20 a =
    30 goto 70
    40 print 2
    50 a = a div 2
    60 if (a - 1) = 0 then 180
    70 if mod(a, 2) = 0 then 40
    80 b = 3
    90 c = sqr(a + 1)
    100 if b >= c then 170
    110 if mod(a, b) = 0 then 130
    120 b = b + 2 : goto 100
    130 if ((a div b) * b - a) = 0 then 150
    140 goto 120
    150 print b
    160 a = a div b : goto 90
    170 print a
    180 print "end"

    ReplyDelete
  3. Personally I find the sieve of eratosthenes to be very simple. Of course, memory becomes an issue at some point but as an algorithm it's quite neat.

    ReplyDelete

Post a Comment