Prime sieve code problem

this bellow code is printing all natural numbers what is the problem I can’t figure out

#include

using namespace std;

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

return;

}

int main()
{
int n;
cin>>n;
int p[n];
primenumbers(p,n);
for(int i=0;i<n;i++)
{
if(p[i]=1)
cout<<i;
}
return 0;
}

Hey @aman_81200
Please share ur code in Coding Blocks IDE

Hey @aman_81200

     for(int i=0;i<n;i++)
    {
        if(p[i]==1) //== here
            cout<<i;
    }

Got it
Thank you for the help :smiley:

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.