Okay I have sat down and am now really confused as why this program is not working. It's supposed to start at array subscript 2 and evertime an array element if found whose value is 1, then loop throuh the remainder of the array and set to zero every element whose subscript is a multiple of the subscript for the element with value 1. For array subscript 2, all emelents beyond 2 in the array that are multiples of 2 will be set to zero (subscripts 4, 6, 8, 10, etc).
Code:// The Seive of Eratosthenes #include <iostream> using std::cout; using std::cin; // Prototypes int main() { const int arraySize = 30; int array[ arraySize ] = { 0 }; for( int i = 2; i < arraySize; i++ ) for( int j = 0; j < arraySize; j++ ) if( array[ j ] == 0 ) if( j % i ) array[ j ] = 1; cout << "Prime numbers are: "; // output subscripts of array whose value = 1 for( int i = 0; i < arraySize; i++ ) if( array[ i ] == 0 ) cout << i << ' '; cin.get(); return 0; }