sieve - <<" the list is"<< endl...

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

This note was uploaded on 10/28/2010 for the course CSCI 1113 taught by Professor Staff during the Spring '08 term at Minnesota.

Ask a homework question - tutors are online