Check out example codes for "eratosthenis sieve in c++". It will help you in understanding the concepts better.

Code Example 1

void eratosthenes_sieve(int N){
	bool primes[N+1];
  	memset(primes, true, sizeof(primes));
  	primes[0] = false;
  	primes[1] = false;
  	for (int p=2; p*p<=N; p++){
      	if (primes[p]){
          	for (int i=p*2; i<=N; i+=p)
              	primes[p] = false;
        }
    }
}

Learn ReactJs, React Native from akashmittal.com