The sieve of Eratosthenes is a method for computing all theprime numbers betweeb
ID: 3617824 • Letter: T
Question
The sieve of Eratosthenes is a method for computing all theprime numbers betweeb 2 and some vale n. The wikipedia descriptionof the Sieve of Eratosthenes (http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes) has a nice animation showing how the algoritim works and a gooddescription of the technique. Read this first. For this problem you will write a program that implements theSieve of Eratosthenes that finds all prime numbers between 2 and avalue stored in a const int names MAX. The skeleton of this programis shown below. Feel free to modify MAX to something smaller whenyou are forst writing the code. This program has an array of bool values crossedOut. We willimplement that act of crossing out a number i as settingcrossOut[i] to be true. There are four parts that you need to complete. First, you need to initialize the array to set all values tobe false, indicating that none of the numbers have been crossed offthe list. After this program prints out the list, for verificatinpurposes. Second, a condition of the main while loop must bespecified. Third, our code needs to cross off all multiples of p. Fourth, your code needs to cross to find the next values of p.if all remaining elements of the crossedOff array are set totrue( that is they are all crossed off), then p should be set toMAX. void display(bool s{}, int size); int main() { const int MAX=1000; bool crossedOff[MAX]; cout<<"The initial list. " <,endl; display(crossedOff, MAX); int p=2; while(2, ... add appropriate condition here..){ cout<<"After crossing off multiples of " <<p <<" the list is : "<<endl; display(crossedOff, MAX); } 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]) cout<<setw(3)<<i; else cout<<" "; } cout<<endl; } The sieve of Eratosthenes is a method for computing all theprime numbers betweeb 2 and some vale n. The wikipedia descriptionof the Sieve of Eratosthenes (http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes) has a nice animation showing how the algoritim works and a gooddescription of the technique. Read this first. For this problem you will write a program that implements theSieve of Eratosthenes that finds all prime numbers between 2 and avalue stored in a const int names MAX. The skeleton of this programis shown below. Feel free to modify MAX to something smaller whenyou are forst writing the code. This program has an array of bool values crossedOut. We willimplement that act of crossing out a number i as settingcrossOut[i] to be true. There are four parts that you need to complete. First, you need to initialize the array to set all values tobe false, indicating that none of the numbers have been crossed offthe list. After this program prints out the list, for verificatinpurposes. Second, a condition of the main while loop must bespecified. Third, our code needs to cross off all multiples of p. Fourth, your code needs to cross to find the next values of p.if all remaining elements of the crossedOff array are set totrue( that is they are all crossed off), then p should be set toMAX. void display(bool s{}, int size); int main() { const int MAX=1000; bool crossedOff[MAX]; cout<<"The initial list. " <,endl; display(crossedOff, MAX); int p=2; while(2, ... add appropriate condition here..){ cout<<"After crossing off multiples of " <<p <<" the list is : "<<endl; display(crossedOff, MAX); } 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]) cout<<setw(3)<<i; else cout<<" "; } cout<<endl; }Explanation / Answer
please rate - thanks #include #include using namespace std; void display (bool s[], intsize); int main() { const int MAX = 100; bool crossedOff[MAX]; int i, s,j; for (i = 0; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.