Remember before also wrote, at that time can not write is to read someone else's answer to write out, today again write found still won't write, it seems that the last time is not learned ah, but think about it or to come up with a not so good method, fortunately, they straighten out the idea, is their own research out of the results.
Output 1000 in the prime, then only need to take out a number each time, and then divide the number from 2 to its own, see the remainder, if the remainder has 0 of the case, then must not be prime, if all except the discovery there is no remainder of 0, then must be prime.
For example, to determine whether 7 is a prime, must see 7%[2,6] results.
Easy to find, not prime this condition is relatively easy to meet, because as long as there is a remainder of 0 can be judged, then in the program is so judged.
There is another problem, if a 7%[2,6] in the process there is a 0 of the situation, then you do not have to judge, because there is no need, you can directly break
There is one more question that is clear in the comments.
int main (void) { /* output 1000 or less prime */int m;int n;for (n=2;n<=1000;n++) {for (M = 2; m < n; m++) {if (n% m = = 0) {break; }}/* A number is a prime or not a prime process will arrive here how to distinguish between these two situations? If it is a prime number, then must be into the loop, then must meet M<n and did not have time to execute m++, because it is the prime number of break. So m<n must be able to launch n is not prime. If a number is a prime, then it means that the inner for loop is gone and the reason for the walk is because the condition of m<n is not satisfied then the M must be equal to n at this time. So m==n must be able to launch n is prime number */if (m==n) {printf ("%d", n);}} return 1;}
Prime number within 1000 of output