Advertisement
thinhckhcmus

KT So Nguyen To

Aug 5th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int ktsonguyento(int &n)
  4. {
  5. int dem = 0;
  6. cout << "nhap so duong kiem tra = ";
  7. cin >> n;
  8. if (n < 2)
  9. {
  10. cout << "dieu kien khong hop le";
  11. }
  12. for (int i = 2; i <= sqrt(n); i++)
  13. {
  14. if (n%i == 0)
  15. {
  16. dem++;
  17. }
  18. }
  19. if (dem == 0)
  20. return true;
  21. else
  22. return false;
  23.  
  24. }
  25. void main()
  26. {
  27. int n;
  28. if (ktsonguyento(n) == true)
  29. cout << n << " la so nguyen to";
  30. else
  31. cout << n << "khong phai la so nguyen to";
  32. system("pause");
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement