Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- bool esDivisor(int a, int b)
- {
- return b % a == 0;
- }
- bool esPerfecto(int num)
- {
- int aux = 0;
- for(int a = 1; a < num; a++)
- {
- if(esDivisor(a, num))
- {
- aux += a;
- }
- }
- return aux == num;
- }
- int main()
- {
- int num;
- cout << "Introduzca un numero entero positivo: ";
- cin >> num;
- if(num < 0) {
- return 1;
- }
- cout << "El numero " << num << (esPerfecto(num) ? "" : " no") << " es perfecto" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement