Skip to content

Instantly share code, notes, and snippets.

@KarlHerler
Created December 13, 2013 14:43
Show Gist options
  • Save KarlHerler/7945290 to your computer and use it in GitHub Desktop.
Save KarlHerler/7945290 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <time.h>
void main() {
while (1) {
clock_t start, end;
double runTime;
start = clock();
int i, num = 1, primes = 0;
while (num <= 10000) {
i = 2;
while (i <= num) {
if(num % i == 0) { break; }
i++;
}
if (i == num) { primes++; }
num++;
}
end = clock();
runTime = (end - start) / (double) CLOCKS_PER_SEC;
printf("This machine calculated all %d prime numbers under 10000 in %g seconds\nLets do that again\n", primes, runTime);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment