Segmentation fault in my code

I have written a code for seive of entra but it always shows segmentation error, i have used long long int still, tell me my error :-

#include
using namespace std;
int main() {
long long int arr[5000000];
for(long long int i=0;i<=5000000;i++)
{
arr[i]=1;
}
for(long long int i=4;i<=5000000;i=i+2)
{
arr[i]=0;
}
for(long long int i=3;i<=5000000;i++)
{
if(arr[i]==1)
{
for(long long int j=i*i;i<=5000000;j=j+i)
{
arr[i]=0;
}
}
}
arr[0]=0;
arr[1]=0;
arr[2]=1;
for(long long int i=0;i<=20;i++)
{
if(arr[i]==1)
{
cout<<i<<endl;
}
}
return 0;
}

Hi @Paritosh007 you have declared an array of size 5000000 hence the range of the array would be 0 - 4999999 but you are trying to access the index 5000000 in your for loop. Increase the size of the array by 1 to overcome this problem.
Next time please save your code on ide.codingblocks.com and share the link.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

even after increasing the array size, the problem remains the same. Resolve this

https://codeshare.io/aroM7K