Hi
The homework is to implement the program and make it run up to 200
Here is the homework:
Check the attachment for a better picture of the code
Problem Solving with Vectors: Example:
Sieve of Erastothenes:
The basic idea behind the algorithm is to take a list of all the positive integers and strike out those that cannot possible be prime numbers. When those are removed, the remaining values must therefore be prime. Suppose we want to discover the prime numbers less than 20.
An index will move through the collection starting at the beginning, that is 2. Starting from this position, which is a prime number, eliminate all multiples of 2.
Next we advance the index to the next position that has not been eliminated, namely 3. Again, we eliminate all multiple of three, and so on.
void sieve(vector<int> &values)
{ unsigned int max = [login to view URL]();
int i;
// first initialize all cells
for (i =0; i < max; i++) values[i]= i;
//now search for non-zero cells
for (i=2; i*i <= max; i++) { if (values[i] !=0)
for ( int j =i+i; j < max; j+=i) values[j] =0;
} }