orlandoju

Ejer5_tp4

Apr 24th, 2022
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. /*
  2. Hacer un programa que permita ingresar una lista de números positivos, negativos o cero hasta que la diferencia entre el máximo y el mínimo sea mayor a 10. Calcular e informar:
  3. La cantidad de números que componen la lista.
  4. */
  5. // Comentarios:
  6.  
  7. #include <iostream>
  8. using namespace std;
  9.  
  10. int main(void){
  11.  
  12.         int n;
  13.         int cantidad=0;
  14.         int nummaximo=0;
  15.         int numminimo=0;
  16.  
  17.         int resta=0;
  18.         bool numero=false;
  19.  
  20.         cout<<"Ingrese numeros hasta que la diferencia de numeros sea mayor a 10: " <<endl;
  21.         cin>>n;
  22.  
  23.  
  24.         while(resta<10)
  25.         {
  26.             cantidad++;
  27.             if(numero==false)
  28.             {
  29.                 nummaximo=n;
  30.                 numminimo=n;
  31.                 numero=true;
  32.             }
  33.             else{
  34.                 if(n>nummaximo)
  35.                 {
  36.                 nummaximo=n;
  37.  
  38.                 }
  39.                 else
  40.                     {
  41.                     if(n<numminimo)
  42.                     {
  43.                         numminimo=n;
  44.                     }
  45.                 }
  46.             }
  47.             resta=nummaximo - numminimo;
  48.             if(resta<10)
  49.             {
  50.                 cin>>n;
  51.             }
  52.  
  53.  
  54.         }
  55.  
  56.         cout<<"La cantidad de numeros que componen la lista es: "<<cantidad<<endl;
  57.         cout<<"la diferencia es: " <<resta<<endl;
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment