fork download
  1. #include <stdio.h>
  2. #define N 50
  3. int main()
  4. {
  5. int i, j;
  6. int n, a[N + 1];
  7. for (i = 0; i < N; ++i)a[i] = 1;
  8. printf("n = ");
  9. scanf("%d", &n);
  10. for (i = 2; i <= N; ++i)
  11. for (j = 2 * i; j <= N; j += i)
  12. a[j] = 0;
  13. for (i = 2; i <= N; ++i)if (a[i] == 1)printf("%d ", i);
  14. return 0;
  15. }
Success #stdin #stdout 0s 1836KB
stdin
50
stdout
n = 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47