TestPrimes.cpp

  1. /*
  2. TestPrimes.cpp — Francisco Cascales — 2017-12-08
  3.  
  4. $ sudo apt-get install build-essential
  5. $ g++ TestPrimes.cpp -o TestPrimes.exe
  6. $ ./TestPrimes.exe
  7. */
  8.  
  9. //#include <iostream>
  10. #include <stdio.h>
  11. #include <time.h>
  12.  
  13. #include "Primes.cpp"
  14.  
  15. //-----------------------------------------------
  16.  
  17. int prueba1() {
  18. int count = 0;
  19. Primes primes;
  20. while (primes.hasNext()) {
  21. int prime = primes.next();
  22. ////System.out.println(prime);
  23. count++;
  24. if ((count % 1000000) == 0) {
  25. printf("%d ", count/1000000); //cout << count/1000000 << " ";
  26. }
  27. //if (count >= 50) break;
  28. }
  29. printf("\nCOUNT=%d\n", count); //cout << "\nCOUNT=" << count << "\n";
  30. primes.close();
  31. }
  32.  
  33. //-----------------------------------------------
  34.  
  35. int main() {
  36. clock_t start = clock();
  37. prueba1();
  38. double elapsed = (clock() - start)/CLOCKS_PER_SEC;
  39. printf("ELAPSED %.2f segundos\n", elapsed); //cout << "ELAPSED=" << elapsed << " segundos\n";
  40. return 0;
  41. }
  42.  

Proinf.net