# Thread: Unsure as to why Prime must be defined.

1. ## Unsure as to why Prime must be defined.

Morning,

I bought the book, "Learn C on the Mac"
So far have been enjoying it but have become stumped at one section.
I was hoping someone could help.

Its to do with the exercise on prime numbers in chap 6.
Regarding the loop to determine whether a number is prime - to me it sounds like the program is able to make out what a prime number is yet we still need to prove a number is a prime.
am i wrong in thinking this.

Code:
```int main (int argc, const char * argv[]) {
bool    isPrime;
int     startingPoint, candidate, last, i;

startingPoint = 24;

if ( startingPoint < 2 ) {
candidate = 2;
}
else if ( startingPoint == 2 ) {
candidate = 3;
}
else {
candidate = startingPoint;
if (candidate % 2 == 0)             /* Test only odd numbers */
candidate--;
do {
isPrime = true;                 /* Assume glorious success */
candidate += 2;                 /* Bump to the next number to test */
last = sqrt( candidate );       /* We'll check to see if candidate */
/* has any factors, from 3 to last */
/* Loop through odd numbers only */
for ( i = 3; (i <= last) && isPrime; i += 2 ) {

//  Here it looks as
//though the program can deduce whether a number is prime
//yet we still need to tell it what a prime number is.
//    - the "&& isPrime" sounds as though it can deduce
//  whether a number is prime

if ( (candidate % i) == 0 )

isPrime = false;
}
} while ( ! isPrime );
}

printf( "The next prime after %d is %d. Happy?\n",
startingPoint, candidate );
return 0;
}```

Thanks,
/84.

2. Thing about C is that it knows nothing you don't teach it... and it's a major idiot, you have to tell it literally everything in little tiny steps and in the correct order. By the time it's on line 11, line 10 is forgotten...

So by the time your code gets to the if(candidate % i) part it doesn't even know what it's actually testing, all it can tell you is True or False.

Trust me, it has absolutely no freaking clue what a prime number is.

3. C doesn't know what a prime number is, but because of the testing done in this part of the code, your program now can tell:

Code:
```/* has any factors, from 3 to last */
/* Loop through odd numbers only */
for ( i = 3; (i <= last) && isPrime; i += 2 ) {
if ( (candidate % i) == 0 )
isPrime = false;
}```
At the end of that loop, every odd number from 3 to last, has been divided into your candidate number. If nothing divides evenly into it, then it's prime. By that test alone, the program "knows" what a prime number is.