Wednesday, October 22, 2008

4-11-liang.cpp

Debugged example from class (W week 4):

#include <iostream>
using namespace std;

const int NUMBER_OF_PRIMES = 50;
const int NUMBER_OF_PRIMES_PER_LINE = 10;

int main(){

int count = 0; // Count the number of prime numbers
int number = 2; // A number to be tested for primeness
bool isPrime; // Is the current number prime?
int divisor; // loop control var

cout << "The first 50 prime numbers are \n";

//generate 50 primes
while (count < NUMBER_OF_PRIMES){
// Test if number is prime
divisor = 2;
while (number % divisor != 0)
divisor++;
// prime, if divisor == number
isPrime = (divisor == number);

//if number is prime, then print
if (isPrime){
//found one more
count++;
//print in table
if (count % NUMBER_OF_PRIMES_PER_LINE == 0){
// Print & go to new line
cout << number << endl;
}
else
cout << number << " ";
}

//generate next potential prime
number++;
}
}

Project 3 Discussion

Post your questions (and answers) about project 3 by adding a Comment to this blog entry.

Wednesday, October 15, 2008

How to Subscribe

If you have a question about a project, add a comment to the project post. Anyone in class with an answer may reply-- our own version of the wisdom of crowds and crowdsourcing.

You can subscribe to this blog's RSS feed by using Firefox's Live Bookmarks feature. Then all new posts will be "pushed" to your browser. Here's how to do it:

1. In Firefox choose Bookmarks > Organize Bookmarks, and create a "Feeds" folder on the bookmarks toolbar.

2. Open this blog in Firefox, scroll to the bottom and click on "Subscribe to: Posts (Atom)". A new page will open in the browser: select Live Bookmarks in the drop-down list, and click Subscribe Now. Add the bookmark to your Feeds folder. Presto!

The drawback to using Live Bookmarks is that the bookmarks exist only on the computer you used to subscribe. An alternative is to use a hosted feed reader such as Google Reader. Then your feeds are stored in the "cloud" and may be accessed from any machine by logging in to your Google account.