fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int M = 12;
  5. int Primes[M + 1];
  6. for (int i = 0; i <= M; i++)
  7. Primes[i] = 1;
  8. for (int i = 2; i * i <= M; i++) {
  9. if (Primes[i]) {
  10. int t = i * i;
  11. while (t <= M) {
  12. Primes[t] = 0;
  13. t += i;
  14. }
  15. }
  16. }
  17. for (int i = 2; i < M; i++)
  18. if (Primes[i])
  19. printf("%d ", i);
  20. return 0;
  21. }
  22.  
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
2 3 5 7 11