Advertisement
Abelsor

Semana 4 - Ejercicio 11

Feb 23rd, 2022
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. /*
  2.                         Semana 4 - Ejercicio 11
  3.     Dado un nΓΊmero n, imprimir en pantalla sus divisores.
  4. */
  5.  
  6. #include<iostream>
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.     float n;
  13.    
  14.     do{
  15.         cout<<"Ingrese un numero entero y positivo: ";
  16.         cin>>n;
  17.     }
  18.     while(int(n)!=n or n<0);
  19.    
  20.     cout<<"Los divisores de "<<n<<" son: "<<endl;
  21.    
  22.     // Buscamos los divisores de 'n'
  23.     for(int i=1 ; i<=n ; i++){
  24.         if(int(n)%i==0)   // Como 'n' es de tipo 'float', debemos trabajar con su parte entera para usar el operador '%'
  25.             cout<<i<<endl;
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement