From abe764f3aea25ac89dfb7dc43b8763c01190bcdf Mon Sep 17 00:00:00 2001 From: Carlos Amedee Date: Wed, 17 Aug 2011 19:34:25 -0400 Subject: [PATCH] Added a real readme file. Removed the 6th case file. --- README | 0 README.markdown | 4 ++++ makefile | 15 +++++++++++++++ primes6.cpp | 33 --------------------------------- 4 files changed, 19 insertions(+), 33 deletions(-) delete mode 100644 README create mode 100644 README.markdown create mode 100644 makefile delete mode 100644 primes6.cpp diff --git a/README b/README deleted file mode 100644 index e69de29..0000000 diff --git a/README.markdown b/README.markdown new file mode 100644 index 0000000..acf5522 --- /dev/null +++ b/README.markdown @@ -0,0 +1,4 @@ +## Prime number blog post + +This repository contains the sample files from a [blog post](http://www.cagedmantis.com/2011/07/16/prime-numbers-from-0-to-n/) about +prime numbers. diff --git a/makefile b/makefile new file mode 100644 index 0000000..db3d61c --- /dev/null +++ b/makefile @@ -0,0 +1,15 @@ + +case1: primes1.cpp + g++ -o case1 primes1.cpp + +case2: primes2.cpp + g++ -o case2 primes2.cpp + +case3: primes3.cpp + g++ -o case3 primes3cpp + +case4: primes4.cpp + g++ -o case4 primes4.cpp + +case5: primes5.cpp + g++ -o case5 primes5.cpp diff --git a/primes6.cpp b/primes6.cpp deleted file mode 100644 index 5cf61c2..0000000 --- a/primes6.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include -#include - -using namespace std; - -int main(int argc, char *argv[]) -{ - if (argv[1] == NULL) - return 0; - const int TOP = atoi(argv[1]); - std::cout << "Prime Numbers from 0 - " << TOP << ": "; - - const int newTop = ((TOP/2)-1+TOP%2); - - //cout << newTop << endl; - bool* sieve = new bool[newTop+1]; - - std::fill_n(sieve, newTop+1, 1); - - for (int i = 2; i <= (int)pow(newTop, 0.5); ++i) { - if (sieve[i] == 0) { - std::cout << i << " "; - for (int j = i; j <= TOP; j+=i) { - sieve[j] = 0; - } - } - } - delete[] sieve; - return 0; -} - -