Advertisement
nguyenhappy92

Liệt kê tất cả ước số của số nguyên dương n.

Sep 18th, 2015
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1.  
  2. // Liet kê tat ca uc so cua so nguyên duong n.
  3. // Khai bao thu vien
  4. #include<stdio.h>
  5. #include<conio.h>
  6. int soNT(int n);
  7. void main()
  8. {
  9. int n;
  10. scanf("%d",&n);
  11. for(int i=1;i<=n;i++)
  12. {
  13. if(n%i==0)
  14. if(soNT(i)==1)
  15. printf("%d\t",i);
  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. dem++;
  25. }
  26. if(dem==2)
  27. return 1; // la so nguyen to
  28. else
  29. return 0; // khong la so nguyen to
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement