#include <iostream>
using namespace std;
int sumaDivisoresPropios(int num) {
int suma = 0;
for (int i = 1; i <= num / 2; ++i) {
if (num % i == 0) {
suma += i;
}
}
return suma;
}
int main() {
int N;
cout << "Ingresa un número entero positivo N: ";
cin >> N;
if (N < 1) {
cout << "Por favor, ingresa un número entero positivo." << endl;
return 1;
}
cout << "Números perfectos entre 1 y " << N << " son:" << endl;
for (int num = 1; num <= N; ++num) {
if (sumaDivisoresPropios(num) == num) {
cout << num << " ";
}
}
cout << endl;
return 0;
}
To embed this program on your website, copy the following code and paste it into your website's HTML: