I'd like to do this without a major restructuring of the code if possible.

[source lang="cpp"]#include <time.h>#include <math.h>#include <iostream>#include <cstdlib>int main(int argc, char*argv[]){ clock_t startTime = clock(); int maxToTest = atoi(argv[1]); int*primes = new int[maxToTest]; primes[0] = 2; int maxPrimeIndex = 0; for (int i=3; i<=maxToTest; i++){ int isPrime = 1; for (int j=0; (isPrime)&&(primes[j] <=sqrt(i)); j++) if (!(i%primes[j])) isPrime = 0; if (isPrime) primes[++maxPrimeIndex]=i; } std::cout << maxPrimeIndex + 1 << " primes <= " << maxToTest << " found in " << (clock() - startTime)/CLOCKS_PER_SEC << " seconds";}[/source]

**Edited by sooner123, 18 December 2012 - 11:07 PM.**