
November 10th, 2007, 09:17 PM
|
|
Registered User
|
|
Join Date: Nov 2007
Posts: 1
Time spent in forums: 19 m 30 sec
Reputation Power: 0
|
|
|
Need help in the following assignemt
Create an array with all elements initialized to 1 (true). Array elements with prime subscripts will remain 1. All other array elements will eventually be set to zero (false). You will ignore elements 0 and 1 in this exercise.
Starting with array subscript 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 subscript is a multiple of the subscript for the element with value 1. For array subscript 2, all elements beyond 2 in the array that are multiples of 2 will be set to zero (subscripts 4, 6, 8, 10, etc.); for array subscript 3, all elements beyond 3 in the array that are multiples of 3 will be set to zero (subscripts 9, 15, 21, etc. - note that 6 and 12 are not listed as they have already been sieved out when considering all multiples of 2); and so on.
instructions:
Write a program that uses an array of 10,000,000 elements to determine and print the prime numbers between a user-specified lower bound and user-specified upper bound. Your program must also have the following features
Your array could either be an int (or unsigned) array, or a bool array. When using a bool array, the above algorithm is easily modified so that the array is initialized to true and numbers that get sieved out are set to false.
|