Hello.
Could anyone help me with a prime number algorithm?
I'm not asking for direct code, but pesudo would be nice...
This is what I currently got
Thanks in advance!Code:int isPrime(const int number){ int i; // variable for the loop double d; // variable to store the division and hold the decimals int x; // variable to help check if a division had decimals if( number <= 1) return 0; // if 'number' is equal to 1, it's not a prime number "The number 1 is by definition not a prime number" - Wikipedia for(i = 2; i != number; ++i){ // 'i' must start at 2 d = number/i; x = d; // and integer cannot hold decimals if(d == x) return 0; // if d and x are equal, then it can't be a prime } return 1; }



LinkBack URL
About LinkBacks





