You're allocating a huge array in stack:
int prime[2000000]={};
Four bytes times two million equals eight megabytes, which is often the maximum stack size. Allocating more than that results in segmentation fault.
You should allocate the array in heap, instead:
int *prime;
prime = malloc(2000000 * sizeof(int));
if(!prime) {
/* not enough memory */
}
/* ... use prime ... */
free(prime);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…