Deepak and Prime Code is Showing segmentation fault

#include<bits/stdc++.h>
using namespace std;
void Sieve(bool *arr)
{
arr[0] = false;
arr[1] = false;
arr[2] = true;

for(long long int i=3;i<=999999;i+=2)
{
arr[i] = true;
}

for(long long int i=3;i<=999999;i+=2)
{
if(arr[i])
{
for(long long int j=ii;j<=999999;j+=2i){
arr[j] = false;
}
}
}
return;
}

int main()
{
bool arr[999999]={0};
memset(arr,true,sizeof(arr));
int n;
cin>>n;
Sieve(arr);
int count=0,ans;
for(long long int i=0;i<=999999;i++)
{
if(arr[i])
{
count++;
if(count==n){
ans=i;
cout<<ans;
break;
}
}
}
return 0;
}

//This code is able to pass few test cases kindly have a look

Hey
Your code has compilation errors
First fix the compilation errors and paste your code in coding blocks ide and pass it on

I have made necessary changes kindly have a look this code is able to pass few test cases

Hey
Your logic of sieve method is wrong
10th prime number is 20 as per your code which is not true
try debugging your code to find where fault lies. If then also you are not able to correct it, do let me know, I will help
P.S use print statements(cout<<) at various points, you will figure out it then

1 Like

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.