Please help me with this... (the sieve of eratosthenes, soe) a prime number inte
ID: 3562919 • Letter: P
Question
Please help me with this... (the sieve of eratosthenes, soe) a prime number integer is any integer that is evenly divisible only by itself and 1. soe is a method of finding prime numbers. it operates as follows: (a) create an array with all elements initialized to 1 (true). array elements with prime index will remain 1. all other array elements will eventually be set to zero. youll ignore element 0 and 1 in this exercise. (b) starting with array index 2, every time an array element is found whose value is 1, loop through the remainder of the array and set to zero every element whose index is multiple of the index for the element with value 1. for array index 2, all elements with indices beyond 2 in the array that are multiple of 2 will be set to zero (indices 4, 6,8, etc); for array index 3, all elements with indices beyond 3 that are multiples of 3 will be set to zero (indices 6, 9, 12, etc); and so on. when this process is complete, the array elements that are still set to one indicate that the index is a prime number. these indices can then be printed. write a program that uses an array of 1000 elements to determine and print the prime numbers between 2 and 999.
Explanation / Answer
/* Name: 4.29.cpp Solved By: The Seeksrs. Description: The sieve of Eratosthenes. determine whether a number is prime or not by using an array. Date: 24/08/03 00:02 */ #include #include using namespace std; int main() { // Variable declarations. const int SIZE = 1000; int prime_number[ SIZE ], counter, divider; // sets all the elements to 1 for( counter = 0; counterRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.