sieve - << " the list...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
// Sieve of Eratosthenes // Author: Your names here. #include<iostream> #include<iomanip> using namespace std; void display (bool s[], int size); int main() { const int MAX = 1000; bool crossedOff[MAX]; // 1. Initialize crossedOut. // Add your initialization code here. cout << "The initial list." << endl; display (crossedOff, MAX) ; // The main loop to cross off numbers. int p=2 ; whiile ( 2. ... add appropriate condition here . .. ) { // 3. Cross off multiples of p. // Add your code for this here. cout << "After crossing off multiples of " << p
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: &lt;&lt; &quot; the list is:&quot; &lt;&lt; endl; display (crossedOff, MAX) ; // 4. Find the next value of p. // Add your code for this step here. } cout &lt;&lt; &quot;The prime numbers are:&quot; &lt;&lt; endl; display (crossedOff, MAX) ; return 0; } void display (bool s, int size) { for (int i=0; i&lt;size; ++i) { if (!s[i]) // if i is not crossed off, print it. cout &lt;&lt; setw(3) &lt;&lt; i ; else // else print the same number of spaces. cout &lt;&lt; &quot; &quot; ; } cout &lt;&lt; endl; }...
View Full Document

Ask a homework question - tutors are online