Advertisement
Nightgod

1000以內的所有質數(10個為1行)

Dec 29th, 2014
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main()
  4. {
  5. int n=1;
  6. int two=2;
  7. printf("%5d ",two);
  8. for(int a=3;a<1000;a++)
  9. {
  10. int count=0;
  11. for(int i=2;i<a;i++)
  12. {
  13. if(a%i==0)
  14. {
  15. count++;
  16. }
  17. }
  18.  
  19. if(count==0)
  20. {
  21. printf("%5d ",a);
  22. n++;
  23. if(n%10==0)
  24. {
  25. printf("\n");
  26. }
  27. }
  28.  
  29. }
  30. printf("\n");
  31. system("pause");
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement