Advertisement
idsystems

CPP_Practica66_Perfectos

Mar 15th, 2013
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. // Program: perfecto.cc
  2. // Author:  Yoan Pinzon
  3. // Date:    Agosto 30, 2006
  4.  
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9. int main(){
  10.    int n;
  11.  
  12.    cout << "Entre n: "; cin >> n;
  13.    for(int i=1; i<=n; i++){
  14.       int s=0;
  15.       for(int j=1; j<i; j++) s+=(i%j==0?j:0);
  16.       if (i==s){
  17.          cout << i << "=";
  18.          for(int j=1; j<i; j++) if(i%j==0) cout << j << "+";
  19.          cout << "\b \n";
  20.       }
  21.    }
  22.  
  23.    return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement