Advertisement
Nasty

Numeros perfectos

Apr 21st, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. bool esDivisor(int a, int b)
  6. {
  7.     return b % a == 0;
  8. }
  9.  
  10. bool esPerfecto(int num)
  11. {
  12.     int aux = 0;
  13.     for(int a = 1; a < num; a++)
  14.     {
  15.         if(esDivisor(a, num))
  16.         {
  17.             aux += a;
  18.         }
  19.     }
  20.     return aux == num;
  21. }
  22.  
  23. int main()
  24. {
  25.     int num;
  26.     cout << "Introduzca un numero entero positivo: ";
  27.     cin >> num;
  28.     if(num < 0) {
  29.         return 1;
  30.     }
  31.     cout << "El numero " << num << (esPerfecto(num) ? "" : " no") << " es perfecto" << endl;
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement