Home > Back-end >  [feeling is a weak-minded problem] a lose prime code, how the whole all wrong
[feeling is a weak-minded problem] a lose prime code, how the whole all wrong

Time:02-19

#include
#include
Int flag [10000], prime [5000].

Int main () {
Memset (flag, 0, sizeof (flag));
Memset (prime, 0, sizeof (prime));
Int cur=0;
For (int I=2; I & lt;=10000; I++) {
if (! Flag [I]) {
Prime [cur++]=I;
For (int j=I; J & lt;=10000; J +=I)
Flag [j]=1;
}
For (int I=0; Prime [I]!=0; I++)
Printf (" % d ", prime [I]);
printf("\n");
return 0;
}

Code is very simple, is the prime erichsen algorithm, flag are prime marks, the prime is a prime number itself, cur cursor is prime array, the algorithm seems to basically do not have what problem, but why I one output is not a 1 3 5 7 this?????? Though I cycle starting 2???????

  • Related