Sieve of eratosthenes

#include
using namespace std;
int main(){
int primes[5000005];
int n;
cin>>n;

 for(int i=0;i<=n;i++){
 	primes[i]=1;
 }
 primes[0]=0;
 primes[1]=0;
 for(int i=2;i*i<=n;i++){
 	if(primes[i]==1){
 		for(int j=2;i*j<=n;j++){
 			primes[i*j]=0;
		 }
	 }
 }
 for(int i=0;i<=n;i++){
 	if(primes[i]==1){
 		cout<<i<<endl;
	 }
 }

}
what’s the error in this code?

Size of your primes array should be 100000005.

it is still showing errors.
the way the i cout the output is correct or not?

Please send the entire code in an online IDE.


I modified your code a bit. Check this out and tell me if you are able to understand it.
I computed the primes array before taking any input.

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.