using namespace std; void display (bool s[], intsize); intmain() { const int MAX
ID: 3617760 • Letter: U
Question
using namespace std;
void display (bool s[], intsize);
intmain() {
const int MAX = 100;
bool crossedOff[MAX];
int i, s,j;
//1. Initialize crossedOut.
// Add your initialization code here.
for (i = 0; i<=100; i++)
{
s[i] = true;
num[i] = i;
}
s[0] = false;
s[1] = false;
cout << "Theinitial list." << endl;
display (crossedOff, MAX) ;
//The main loop to cross off numbers.
int p=2;
//while ( p<max ) ... addappropriate condition here ... ) {
for(i = 1; i<=100; i++)
{
for(p = i;p<=100;)
{
s[p] = false;
p = p*2;
}
}
// 3. Cross off multiples of p.
// Add your code for this here.
cout << "After crossing off multiples of " <<p << " thelist is:" << endl;
display (crossedOff, MAX) ;
// 4. Find the next value ofp. // Add your code for this stephere.
intl=3;
for(i = 1; i<=100; i++)
{
for(l = i; l<=100; l++)
{
s[l] = false;
l = l*3;
}
}
for(p = 0; p<=100; p++)
{
if (s[p] == true)
{
printf("%d ",num[p]);
}
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 isnot crossed off, print it.
cout<< setw(3) << i ;
else
// elseprint the same number of spaces.
cout<< " " ;
}
cout << endl;
}
Explanation / Answer
please rate - thanks // Sieve of Eratosthenes // Author: Your names here. #include #include using namespace std; void display (bool s[], intsize); int main() { const int MAX = 100; bool crossedOff[MAX]; int i, s,j; // 1. Initialize crossedOut. // Add your initialization code here. for (i = 0; iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.