Advertisement
nguyenhappy92

Phân tích thừa số nguyên tố

Oct 23rd, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. // phan tich thua so nguyen to n VD: 6 = 2 va 3
  2. // Khai bao cac ham thu vien neu co
  3. #include<stdio.h>
  4. #include<conio.h>
  5. int nt(int x);
  6. void thuaso(int n);
  7. void main()
  8. {
  9. int n;
  10. scanf("%d",&n);
  11. thuaso(n);
  12.  
  13. }
  14. void thuaso(int n)
  15. {
  16. for(int i=1;i<=n;i++)
  17. {
  18. if(nt(i))
  19. {
  20. if(n%i==0)
  21. {
  22. printf("%d ",i);
  23. n=n/i;
  24. }
  25. }
  26. }
  27. }
  28. int nt(int x)
  29. {
  30. int dem=0;
  31. for(int i=1;i<=x;i++)
  32. {
  33. if(x%i==0)
  34. {
  35. dem++;
  36. }
  37. }
  38. if(dem==2)
  39. return 1;
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement