CSC170: Introductory Computer Programming

Homework Assignment 4

Due: Tuesday, July 27

You will play with prime numbers in this assignments. Some interesting facts and resources can be found at The Prime Pages. You need to create a user interface to let user input a positive integer and output a table of all the prime numbers less than the specified integer. For example, all the prime numbers under 50 are listed in the following table.

235
71113
171923
293137
4147
You will learn

Requirements

There are two parts of this assignment:
  1. Use simple primality test to find the prime numbers. You will use a double loop and the inner loop is for primality test.
  2. Use Eratosthenes' sieve to find the prime numbers. You need to use an array to keep track of proper multiples.
Here are the grading criteria:
  1. With both methods, your result should be correct. No composite numbers will be output and no prime number will be left out. 2pt.
  2. You have a usable UI and you should verify user input (e.g. use while to check user input indefinitely): only positive integers are allowed. You should lay out the table (number of rows and cols) reasonable well. 1pt.
  3. You implement the sieve method correctly. It should give the right answer and it should run much faster than the simple primality test method. 1pt.
  4. You have good coding style, including sensible variable names, proper indentations, etc. 1pt.

Bonus Points

You will get 40 points (all the points for homework assignments) if you break the Largest Known Prime record.

Hints

To see how the Eratosthenes' sieve works, try this page.

Hand-in Procedure

Do not FTP your home page and relevant other HTML and image files to your course account on mail.rochester.edu until you have received your grade .
Note that directories on mail.rochester.edu are scanned regularly. Any person who makes active homework files accessible to others is violating the homework requirements and forfeits their grade.

Instead,

Plagiarism

There are some JavaScript programs doing primality test on the net. You can certainly take a look at how other people do it. But do not copy their code. If plagiarism is found, you will not only lose the points for this assignment, you may also face additional penalties from the University.