Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <stdlib.h>
  4. #define N 10000
  5.  
  6. int main ()
  7. {
  8.     int i,j=1;
  9.     int *array;
  10.  
  11.     array = (int *) malloc(sizeof(int)*N);
  12.  
  13.     for (i=0;i<N;i++)
  14.     {
  15.         array[i]=i+2;
  16.     }
  17.     for (i=0;array[i]<sqrt(N);i++)
  18.     {
  19.         if (array[i]!=0)
  20.         {
  21.             while ((array[i]*j)<N)
  22.             {
  23.                 array[i+j*array[i]]=0;
  24.                 j++;
  25.             }
  26.         }
  27.         j=1;
  28.     }
  29.     for(i=0;i<N;i++)
  30.     {
  31.         if (array[i]!=0)
  32.         {
  33.             printf("%d ", array[i]);
  34.         }
  35.     }
  36.     free(array);
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement