Homework 4, Finding Primes.

Short Description:

Write a program that will find all the prime numbers between 2 and some maximum value.

Goals

When you finish this homework, you should have:

Formal Description

For this program we will implement a version of the Sieve f Eratosthenes. This is an algorithm that finds prime numbers by eliminating the numbers that are divisible by know primes.

The basic algorithm is

  1. Write down all of the numbers between 2 and n, the largest possible prime you are interested in
  2. Set the current prime to be 2.
  3. While the current prime is less than the square root of the largest possible prime
  4. Cross off all of the multiples of the current prime.
  5. Find the next number that has not been crossed off, this is the new current prime.
  6. List all of the numbers, 2 and higher, that have not been crossed off. These are the prime numbers.

We will write this program in a series of guided steps. Please follow these steps. Your code is expected to be the same structure as mine.

  1. Download the starting files
  2. Declare the main array and initialize it.
  3. Add a single step sieve function
  4. Find the next available prime
  5. Build a list of primes.
  6. Turn off debugging and test your program against the list of primes provided
  7. Make sure you add proper documentation and submit your program.

Required Files

A single tar file containing the source code and makefile for this program.

Submission

Submit the assignment to the D2L folder homework 4 by the due date.