sandy.bridge
				
				
			 
			
	
	
	
		
	
	
			
		
		
			
			
				
- 797
- 1
Hey guys, just looking for an explanation for the following algorithm. It is in my textbook, and there isn't really an explanation. I don't really see how the algorithm works, but I will add what I do know, and hopefully one of you can help. Thanks.
	
	
	
    
	
		
Furthermore, I am not entirely sure why count was initialized at the beginning of the algorithm, I never saw it used.
				
			
		PHP:
	
	//this initial declarations produces an array with N elements.
int N = 40;
bool table[N];
int count = 0;
//this while loop assigns every element in the array to true.
int i = 0;
while (i < N)
{
     table[i]=true;
     i=i+1;
}
//from here is where I get lost.
table[0]=false; //assigns false value to the first element in the array.
i=2; //starts the next loop at 2.
while (i < N)
{
     if (table[i]
     {
          cout << i << " is prime." << endl;
          int j = 2*i;
          while (j < N)
          { 
              table[j]=false;
               j=j+i;
          }
     }
i=i+1;
}Furthermore, I am not entirely sure why count was initialized at the beginning of the algorithm, I never saw it used.
 
 
		 
 
		