Created
December 13, 2013 14:43
-
-
Save KarlHerler/7945290 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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