Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using the Sieve of Erastothenes calculate the prime numbers from 2 to 200: The S

ID: 3576179 • Letter: U

Question


Using the Sieve of Erastothenes calculate the prime numbers from 2 to 200: The Sieve of Erastothenes is an ancient algorithm that generates prime numbers. Consider the list of numbers from 2 to 10 as follows: (NOTE YOUR requirement is to calculate primes from 2 to 200 using this technique) The algorithm starts with the first prime number in the list, which is 2. and then iterates through the remainder of the list, removing any number that is a multiple of 2 (in this case. 4, 6, 8, and 10). leaving We then repeat the process with the second prime number in the list, which is 3. and then iterate through the remainder of the list, removing any number that is a multiple of 3 (in this case 9). leaving We then repeat starting with each successive prime number. When your program finishes, the numbers that remain in the list are all prime numbers. Implement this algorithm using an ArrayList of integers that is initialized to the values from 2 to 200. OUTPUT requirements Output all intermediate steps and final list of primes: 2 3 4 5 6 7 8 9 10 11 12 ... 200 (all numbers. 2 -200 in a row) 2 3 5 7 9 11 13 15 ...199 (list with all multiples of second element (2) removed) 2 3 5 7 9 11 13 17.. 199 (list with all multiples of third remaining (5) clement removed) ... (continue to output successive rows) Last line should read Prime Numbers = 23 5 7 ....(up to 199 showing all prime numbers)

Explanation / Answer

#include <bits/stdc++.h>
using namespace std;

void SieveOfEratosthenes(int n)
produce a mathematician array "prime[0..n]" and initialize
// all entries it as true. a worth in prime[i] can
// finally be false if i isn't a chief, else true.
bool prime[n+1];
memset(prime, true, sizeof(prime));

for (int p=2; p*p<=n; p++)
{
// If prime[p] isn't modified, then it's a chief
if (prime[p] == true)
  
}

// Print all prime numbers
for (int p=2; p<=n; p++)
if (prime[p])
cout << p << " ";
}

// Driver Program to check on top of operate
int main()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote