This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Generating Prime Numbers CSc 1253: Programming Project # 4 Sieve of Eratosthenes Out: 11/2 Due: 11/12 by 11:50 PM Learning Objectives • To implement a modular design, • Using functions with arrays as formal parameters, • Using nested loops Definition 1. The Sieve of Eratosthenes is an algorithm for making tables of primes. The integers from 2 to the highest number, n, you wish to include in the table are sequentially written down. Numbers which are divisible by 2 (every second number) are then crossed out. Find the smallest remaining number . It is 3. Cross out all numbers which are divisible by 3 (every third number). Find the smallest remaining number . It is 5. So cross out all numbers which are divisible by 5 (every fifth number). Continue until you have crossed out all numbers divisible by floorleft √ n floorright , where floorleftfloorright is the floor function; that is, the greatest integer less than or equal to √ n . The numbers remaining are prime. Subfunctions In addition to the main function, your program will consist of the following functions: /* * fills the array, primes, with all the prime * numbers between 2 and n inclusive using the Eratosthenes * sieve algorithm. The number are placed in ascending order * in the array and the size variable is the number of * prime numbers less than or equals to n: primes[0] = 2, * primes[1] = 3, primes[2] = 5, primes[3] = 7, ... * @param primes  the array containing the prime numbers * @param n  the smallest integers greater than or equals * to the largest prime number generated * @param size  the number of prime numbers generated....
View
Full Document
 Fall '08
 Staff
 Prime Numbers, Prime number, Duncan

Click to edit the document details