Advertisement
thinhckhcmus

KT So Hoan Thien

Aug 5th, 2019
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #define MAX 100000
  3. using namespace std;
  4. void nhapsonguyenduong(int &n)
  5. {
  6. do
  7. {
  8. cout << "Nhap so de kiem tra = ";
  9. cin >> n;
  10. if (n < 0 || n>MAX)
  11. {
  12. cout << "so nhap vao khong hop le, kiem tra lai";
  13. }
  14. } while (n < 0 || n>MAX);
  15. }
  16. int kiemtrasohoanhao(int &n)
  17. {
  18. int sum = 0;
  19. for (int i = 1; i <=n/2; i++)
  20. {
  21. if (n%i == 0)
  22. {
  23. sum = sum + i;
  24. }
  25. }
  26. if (sum == n)
  27. return true;
  28. else
  29. return false;
  30. }
  31. void main()
  32. {
  33. int n;
  34. nhapsonguyenduong(n);
  35. if (kiemtrasohoanhao(n) == true)
  36. cout << n << " day la so hoan hao" << endl;
  37. else
  38. cout <<n<< "day khong phai la so hoan hao";
  39. system("\npause");
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement