CS 1500-1, Spring 2008
Lab 3

Read and study the directions before the day of the lab. Try to rehearse mentally what you will be doing. Better still, if you have time, get online and actually rehearse some of the steps.

The goal of this exercise is to develop an interactive program that uses loops.

A prime number is a number greater than 1, whose only divisors are 1 and itself.

Write a program that finds and prints all prime numbers less than or equal to n, where n is a number input by the user. A template for starting the program is here. A script that shows the required format of the output is available here.

For more information about prime numbers:
Wikipedia
MathWorld

Individual steps:

  1. Think through how you might check for primes. One way to solve this is with a doubly-nested loop. The outer look will iterate from 2 to n, while the inner loop checks to see if the current integer is prime by checking for divisors. You may use the template provided to help you organize your program.

  2. Make a script (you could call it lab03.script) testing your program for n = 100. Be sure to filter the script and directed at the bottom of the script page.

  3. Upload your source code (lab03.cpp) and your script (lab03.script) to the CSHomework system. Each student should upload a copy under their own name.

  4. Hand in a print out of your source code (lab03.cpp). Be sure that your names are on it.



DUE DATES:

For the due dates, see the class schedule.