I wrote a program to count from 3 to the highest long long int my compiler can handle. Only problem is, I'm not even sure if it works as I get a 'floating point exception' error on compile.Code:#include<stdio.h> #include<math.h> long long int testNum; long long int testAgainst; short int isNumPrime; int isPrime(long long int testNum, long long int testAgainst); int main() { //9223372036854775807 = largest int for(testNum=3;testNum<9223372036854775807;testNum++) { if(isPrime(testNum,testAgainst)==1) { printf("%lli\n",testNum); } } return 0; } int isPrime(long long int testNum,long long int testAgainst) { int isNumPrime; for(isNumPrime=1;testAgainst!=sqrt(testNum);testAgainst++) { if(testNum%testAgainst==0) { isNumPrime=1; } else { isNumPrime=0; break; } } return isNumPrime; }
I'm guessing it's for one of three reasons, but I can't point it out, maybe someone can help me there?
Trap representations of signed types
Overflow on signed types
Division by zero
If I divided by zero, I would be so happy.



LinkBack URL
About LinkBacks




