trojanxem

Untitled

Mar 7th, 2012
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.42 KB | None | 0 0
  1. // Liczby pierwsze by troyaax
  2.  
  3. #include <conio.h>
  4. #include <cstdio>
  5. #include <cmath>
  6.  
  7.  
  8.  
  9. int main()
  10. {
  11. int zakres;
  12. printf ("Podaj zakres: \n");
  13. scanf("%d", &zakres);
  14.  
  15.  
  16.  
  17. int f=zakres/2;
  18.  
  19. bool m[zakres];
  20. for(int n=0;n<zakres;n++) m[n]=1;
  21.  
  22. for(int k=2;k<f;k++)
  23. if(m[k]) for(int j=k+k;j<zakres;j+=k) m[j]=0;
  24.  
  25.  
  26.  
  27. for(int i=2;i<zakres;i++)
  28. {
  29. if(m[i])
  30. {
  31. printf("%d ", i);
  32.  
  33. }
  34. }
  35.  
  36. getch();
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment