The program is crashing each time I am compiling it.I need to find the 10001 th prime number. I know this is a case of stack overflow but could not solve it.Tell me the solution to the problem.
// 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;
}