Problem: A prime numberis an integer greater than 1 and divisible only by itself
ID: 3610551 • Letter: P
Question
Problem:
A prime numberis an integer greater than 1 and divisible only by itself and thenumber 1. An integer x is divisible by an integery if there is another integer z such x = y *z. The Greek mathematician Erathosthenes gave analgorithm for finding all prime numbers less than some integerN. This algorithm is called the Sieve ofErathosthenes. It works like this: beginning with a list ofintegers 2 through N. The number 2 is the firstprime. The multiples of 2 that is 4, 6, 8, etc. are not primenumbers. We cross these off our list. Then the nextnumber after 3 that is not crossed off is the next prime. Thisnumber is 3. The multiples of three are 9, 12, 15,etc. The first number not crossed off is the next prime whichis 5 and so on. The algorithm continues in this fashion untilwe reach N. All the numbers not crossed off the listare prime numbers.
Write a programusing this algorithm to find all the primes numbers less than theuser supplied number N. Use a vector container for theintegers. Use an array of bool initially set to true to keeptrack of the crossed off numbers. Change the entry to falsefor integers that are crossed off the list.
DISCUSSION
INPUT: The number N
Explanation / Answer
please rate -thanks without vector container- as per my message #include using namespace std; int main() { int i,j,max; bool sieve[400]; coutmax; while (max>0) {coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.