Advertisement
nguyenhappy92

Liệt kê tất cả các số nguyên tố nhỏ hơn n

Oct 6th, 2015
1,096
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. // Liet ke cac so Nguyen To nho hon n
  2. // Khai bao cac thu vien chuong trinh
  3. #include<stdio.h>
  4. #include<conio.h>
  5. int soNT(int n);
  6. void main()
  7. {
  8. int n;
  9. scanf("%d",&n);
  10. for(int i=1;i<n;i++)
  11. {
  12. if(soNT(i)==1)
  13. {
  14. printf("%4d",i);
  15. }
  16. }
  17. }
  18. int soNT(int n)
  19. {
  20. int dem=0;
  21. for(int i=1;i<=n;i++)
  22. {
  23. if(n%i==0)
  24. {
  25. dem++;
  26. }
  27. }
  28. if(dem==2)
  29. return 1;
  30. return 0;
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement