November 21st, 2012, 03:10 PM
prime chekcer doesnt work
A student approached me and asked why his prime checker wouldnt work. I took a look and it should work, imo, for all < 64 bit inputs.
checked for a bunch of primes i could think of 0,1,2,3,4,5,6,7 up to 18446744073709551557, which is supposed to be one of the largest 64 bit primes. Worked.
int isitprime(unsigned long long in)
unsigned long long c;
unsigned long long max = sqrt(in);
if(in <= 1 )
if(in == 2)
for(c=2; c<max; i++)
if(in%c == 0)
Does anyone see a mistake here?
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!