Advertisement
dtung

Untitled

Apr 11th, 2020
587
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.42 KB | None | 0 0
  1. // modification of the original code
  2. #include <stdio.h>
  3.  
  4. int main()
  5. {
  6.     int n;
  7.     printf("Enter the maximum number ");
  8.     scanf("%d", &n);
  9.     printf("Prime numbers are: ");
  10.     for (int i = 2; i <= n; i++) {
  11.         int fact = 0;
  12.         for (int j = 2; j < i; j++)
  13.             if (i%j == 0)
  14.                 fact++;
  15.         if (fact == 0)
  16.             printf("%d ", i);
  17.     }
  18.     printf("\n");
  19.     return 0;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement