每次编译时程序都会崩溃。我需要找到第10001个素数。我知道这是堆栈溢出的情况但无法解决它。告诉我解决问题的方法。
// program to find 10001th prime number.
#include<stdio.h>
#define MAX 1000000
int main()
{
int primes[MAX];
int i,p,isprime;
primes[0]=2;
primes[1]=3;
int primeindex=2;
for(p=5;p<MAX;p=p+2) //iterating over all the odd numbers
{ isprime=1; // assuming that the number chosen is prime
for(i=0;i<primeindex;i++)
{
if(p % primes[i]==0)
isprime=0;
}
if(isprime ==1)
{
primes[primeindex]=p; //updating the list of prime numbers
primeindex ++; // updating the list of prime index
}
}
printf("%d\n",primes[10000]); //supposed to print 10001 prime number
printf(" %d",primeindex);
return 0;
}