csc1253proj04f10

csc1253proj04f10 - Generating Prime Numbers CSc 1253:...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the 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. Sub-functions 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

Page1 / 5

csc1253proj04f10 - Generating Prime Numbers CSc 1253:...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online