Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define MAX 100000
- using namespace std;
- void nhapsonguyenduong(int &n)
- {
- do
- {
- cout << "Nhap so de kiem tra = ";
- cin >> n;
- if (n < 0 || n>MAX)
- {
- cout << "so nhap vao khong hop le, kiem tra lai";
- }
- } while (n < 0 || n>MAX);
- }
- int kiemtrasohoanhao(int &n)
- {
- int sum = 0;
- for (int i = 1; i <=n/2; i++)
- {
- if (n%i == 0)
- {
- sum = sum + i;
- }
- }
- if (sum == n)
- return true;
- else
- return false;
- }
- void main()
- {
- int n;
- nhapsonguyenduong(n);
- if (kiemtrasohoanhao(n) == true)
- cout << n << " day la so hoan hao" << endl;
- else
- cout <<n<< "day khong phai la so hoan hao";
- system("\npause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement