Guest User

Untitled

a guest
Mar 22nd, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.74 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. int isPrime(int n)
  6. {
  7.     if (n % 1 || n < 2) return 0;
  8.     if (n % 2==0) return (n == 2);
  9.     if (n % 3==0) return (n == 3);
  10.    
  11.     float f = (float)sqrt(n);
  12.     for (int i = 5;i <= (int)f; i += 6) {
  13.         if (n % i == 0)
  14.             return 0;
  15.        
  16.         if (n%(i+2)==0)
  17.             return 0;
  18.     }
  19.    
  20.     return 1;
  21. }
  22.  
  23. int main(int argc, char *argv[])
  24. {
  25.     int flag;
  26.  
  27.     int count = 0;
  28.     int min = atoi(argv[1]);
  29.     int max = atoi(argv[2]);
  30.    
  31.     for (int i = min; i < max; ++i)
  32.     {
  33.         if (isPrime(i) == 1)
  34.         {
  35.             printf("%d,", i);
  36.             count++;
  37.         }
  38.     }
  39.  
  40.     printf("\n%d", count);
  41.  
  42.     return 0;
  43. }
Add Comment
Please, Sign In to add comment