1. #include <stdio.h>
  2. #include <math.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5.  
  6. double timetaken=0;
  7.  
  8. float timer(int T){
  9. static double then=0.0;
  10. static double clocks=0;
  11. double now,diff;
  12. now=(double)clock()/((double)(CLOCKS_PER_SEC));
  13. diff=now-then;
  14. if (T <= 0) then=now;
  15. return((float)diff);
  16. }
  17.  
  18. int main(void)
  19. {
  20. timetaken=timer(0);
  21. int numPrimes = 0;
  22. int currentTest = 2;
  23. int isPrime = 1;
  24.  
  25. while (numPrimes<10000) {
  26. for (int i = 2; i < currentTest-1; i++) {
  27. if (currentTest%i == 0){
  28. isPrime = 0;
  29. break;
  30. }
  31. }
  32.  
  33.  
  34. if (isPrime == 1) {
  35. numPrimes = numPrimes + 1;
  36. printf("found prime %i %i\n",numPrimes,currentTest);
  37. }
  38. isPrime = 1;
  39. currentTest = currentTest + 1;
  40. }
  41. timetaken=timer(1);
  42. printf("time taken = %f\n",timetaken);
  43. system("PAUSE");
  44. return 0;
  45. }
  46.