# Perfect number

A number is called perfect if the number is equal to the sum of its divisors (the number itself is not considered a divisor in this case).

## Check Perfect Number

``````#include &lt;iostream&gt;
using namespace std;

int main() {
int number, sum = 0;

cout << "Enter a number to check for perfect: ";
cin >> number;

for (int i = 1; i < number; i++) {
if (number % i == 0) {
sum = sum + i;
}
}

if (sum == number) {
cout << number << " is a perfect number";
}
else {
cout << number << " is not a perfect number";
}

return 0;
}``````
##### Output
``````Enter a number to check for perfect: 28
28 is a perfect number``````

## Perfect Number List (1-n)

``````#include &lt;iostream&gt;
using namespace std;

void checkPerfect(int max) {
int number, min = 1, i, sum = 0;

for (number = min; number <= max; number++) {
sum = 0;
for (i = 1; i < number; i++) {
if (number % i == 0) {
sum = sum + i;
}
}
if (sum == number) {
cout << number << " is a perfect number" << endl;
}
}
}

int main() {
int max;

cout << "Enter the upper bound to find perfect numbers: ";
cin >> max;

checkPerfect(max);

return 0;
}``````
##### Output
``````Enter the upper bound to find perfect numbers: 10000
6 is a perfect number
28 is a perfect number
496 is a perfect number
8128 is a perfect number``````