fork download
  1. void runEratosthenesSieve(int upperBound) {
  2. int upperBoundSquareRoot = (int)sqrt((double)upperBound);
  3. bool *isComposite = new bool[upperBound + 1];
  4. memset(isComposite, 0, sizeof(bool) * (upperBound + 1));
  5. for (int m = 2; m <= upperBoundSquareRoot; m++) {
  6. if (!isComposite[m]) {
  7. cout << m << " ";
  8. for (int k = m * m; k <= upperBound; k += m)
  9. isComposite[k] = true;
  10. }
  11. }
  12. for (int m = upperBoundSquareRoot; m <= upperBound; m++)
  13. if (!isComposite[m])
  14. cout << m << " ";
  15. delete [] isComposite;
  16. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
68
compilation info
prog.cpp: In function ‘void runEratosthenesSieve(int)’:
prog.cpp:2:62: error: ‘sqrt’ was not declared in this scope
       int upperBoundSquareRoot = (int)sqrt((double)upperBound);
                                                              ^
prog.cpp:4:61: error: ‘memset’ was not declared in this scope
       memset(isComposite, 0, sizeof(bool) * (upperBound + 1));
                                                             ^
prog.cpp:7:19: error: ‘cout’ was not declared in this scope
                   cout << m << " ";
                   ^~~~
prog.cpp:14:19: error: ‘cout’ was not declared in this scope
                   cout << m << " ";
                   ^~~~
stdout
Standard output is empty