- Thursday, March 15, at 6:00 PM
- Hardcopy showing pseudocode for the program you are going to write.
- Monday, March 19, at 9:00 AM:
- The finished Scilab code.

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

- be defined in a Scilab source code file named
*count_primes.sci* - be called
*count_primes* - NOT call the built-in Scilab function called "primes"
- take as input two arguments:
- the starting point of the range in which to look (inclusive)
- the ending point of the range in which to look (inclusive)

- return (as output of the function) an integer: the number of primes found between the given starting and ending points (inclusive)
- print out to the screen each prime number as it is found, one per line

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.

- writing out the prime numbers as they are found,
not one per line, but separated by spaces; i.e.,
not like this:
53 59 61

but like this:53 59 61

But 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. - making a table and a graph which show the percentage of prime
numbers within successive decades. That is,
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.