Advertisement
Abelsor

S3_Ejercicio_3

Feb 23rd, 2023 (edited)
626
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int main(){
  4.     int opcion;
  5.     cin>>opcion;// no modifique la instrucción de lectura
  6.     int n,suma = 0;
  7.     cin>>n;// no modifique la instrucción de lectura
  8.    
  9.    if(opcion==1){ // Divisores propios de n
  10.    
  11.         for(int i=1 ; i<n ; i++){
  12.             if(n%i==0){
  13.                 cout<<i<<endl;
  14.             }
  15.         }
  16.    
  17.    }else if(opcion==2){ // Suma de los divisores propios de n
  18.      
  19.         for(int i=1 ; i<n ; i++){
  20.             if(n%i==0){
  21.                 suma += i;
  22.             }
  23.         }
  24.         cout<<suma;
  25.        
  26.    }else if(opcion==3){  // Numeros perfectos
  27.      
  28.       for(int i=1 ; i<=n ; i++){
  29.         suma = 0;
  30.         for(int j=1 ; j<i ; j++){
  31.             if(i%j == 0){
  32.                 suma += j;
  33.               }
  34.           }
  35.           if(suma == i){
  36.             cout<<i<<endl;
  37.           }
  38.       }
  39. }
  40.  
  41.     return 0;// no utilize system(pause)
  42.    
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement