PSICS Fall 2004 Quiz #12

Quiz #12 - 11/18/04
Due by Sunday 12/5 at 11PM (to WebCT)

Submit your solutions to this quiz by dropping in your webct drop box in the box labeled "Quiz12". Let Dave know if you have problems submitting!

Assignment

Simple C++ Progam

Write a C++ program that prints finds and prints out the first twenty prime numbers (the first prime number is 2). You should consider splitting the progam into a few functions, for example you might consider creating a function that is given an integer and returns true only if the integer is a prime number.

The following definition may provide some insight into how to find prime numbers: "A prime number is a natural number greater than 1 that can be divided evenly only by 1 and itself." So you probably want to create a function that determines whether one number evenly divides (remainder is 0) another number. The brute force approach for determining whether n is a prime number would then involve seeing if there is any number between 2 and n-1 that divides n evenly. (There are lots of optmizations you can make to this brute force approach, and lots of more elegant ways to determine whether a number is prime - feel free to explore any of these...).

Submit a single C++ program that will print out the first twenty prime numbers, and include some information about what compiler you used (Visual C++ vs. g++) and anything else we need to know to evalute your program.

Comments are required - make sure we can easily understand what your code is doing!