Deepak and sieve

i dont why it is giving run time error ,please look into this asap;
//code
#include
using namespace std;
int main()
{
int n=5000009;
int p[n]={0};

p[0]=0;
p[1]=0;
p[2]=1;
 int i;
int  count=0;
 int j;
for( i=3;i<=n;i=i+2)
{p[i]=1;
}

for( i=3;i<=n;i=i+2)
{if(p[i])
{

	for( j=i*i;j<=n;j=j+2*i)
	{
		p[j]=0;
	}
}
}
int no,result;
cin>>no;
for(i=0;i<=n;i++)
{
	if(p[i]==1)
	{
		count++;
 }
	if(no==count)
	{
		result=i;
		break;
	}
	
}
cout<<result;

}

paste your code on coding blocks IDE and share the link here and mention your problem link here.

Hi Vijay, try to optimise the code further, for example, make the array global because such large arrays cannot be made inside main function due to limited storage available to main on stack. Otherwise your logic is working fine for arrays of lesser size.