Why am I getting a segmentation error 19?

#include
using namespace std;

void prime_sieve(int a[])
{
a[0]=0;
a[1]=0;
a[2]=1;

//sieve
for(int i=3 ; i<100000 ; i+=2)
{
	if(a[i]==1)
	{
		for(int j=i*i ; j<100000 ; j=j+i)
		{a[j]=0;}
	}
}

}

int main() {

int a[100000]={0};
int n;
cin>>n;
prime_sieve(a);
n--;
if(n==0)
{cout<<'2';}

for(int i=3 ; n>0 ; i=i+2)
{
  if(a[i]==1)
  n--;

  if(n==0)
  cout<<a[i];
}
return 0;

}

@amangupta as per constraints you may have to print upto 5000000th prime number that lies around 10^8 so make your array size of 10^8 and check for primes upto this.