Instructor's solution: count_primes.sci |
It might help some of you to see a program which looks for odd numbers between two bounds. Looking for prime numbers takes more work, but perhaps this will help you to start. |
Your job in this assignment is to write a function which finds all the prime numbers in some range of integers. The function must
The declaration of the function should look like this:
function primes_between = count_primes(lower_bound, upper_bound)
Please document your function so that other people can understand what it does, and how it does it. Part of the grade for this assignment -- and all assignments -- will be based on the internal documentation of the program. When in doubt, pretend that you are going to mail the program to your favorite high-school math teacher. He or she should be able to understand everything (including motivation and any limitations) simply by reading the source code.
53 59 61but like this:
53 59 61But you must never write more than 70 characters in a single line; if the next prime number would go beyond this limit, you must write out a "newline", and start at the beginning of a new line of numbers.
decade percentage which are prime ------------------------------------------------ 0 - 10 10 - 100 100 - 1000 .... ------------------------------------------------
Your table should go to at least 1,000,000; the farther you can take it, the better. Please include the time taken to generate the table.
Make your graph on semilog paper, so that each decade is represented by the same interval on the x-axis.
This page maintained by Michael Richmond. Last modified Mar 6, 2007.
Copyright © Michael Richmond. This work is licensed under a Creative Commons License.