fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. // your code goes here
  5. int n, i, j, count;
  6.  
  7. printf("Enter the limit: ");
  8. scanf("%d", &n);
  9.  
  10. printf("Prime numbers are:\n");
  11.  
  12. for (i = 2; i <= n; i++) {
  13. count = 0;
  14. for (j = 1; j <= i; j++) {
  15. if (i % j == 0)
  16. count++;
  17. }
  18. if (count == 2) // divisible by 1 and itself
  19. printf("%d ", i);
  20. }
  21.  
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0s 5320KB
stdin
100
stdout
Enter the limit: Prime numbers are:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97