orlandoju

Ejer9_tp3

Apr 7th, 2022 (edited)
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main(void)
  5. {
  6.  
  7.     int i,n1,maxneg, minpos;
  8.     bool numpos=false;
  9.     bool numneg=false;
  10.     cout<< " Ingrese la cantidad de 10 numeros: "<<endl;
  11.     cout<<"--------------------"<<endl;
  12.     for (i = 0; i < 10; i++)
  13.     {
  14.         cin >> n1;
  15.         cout<<"--------------------"<<endl;
  16.         if(n1>0 && numpos==false)
  17.         {
  18.             minpos=n1;
  19.             numpos=true;
  20.         }
  21.         else if(n1>0 && numpos==true && n1<minpos)
  22.         {
  23.             minpos=n1;
  24.         }
  25.         if(n1<0 && numneg==false)
  26.         {
  27.             maxneg=n1;
  28.             numneg=true;
  29.         }
  30.         else if(n1<0 && numneg==true && n1>maxneg )
  31.         {
  32.             maxneg=n1;
  33.         }
  34.  
  35.  
  36.     }
  37.     cout<<"--------------------"<<endl;
  38.     cout << "El maximo negativo es:  "<<maxneg<< endl;
  39.  
  40.     cout<<"--------------------"<<endl;
  41.     cout << "El minimo positivo es:  "<<minpos<< endl;
  42.  
  43.  
  44.  
  45.  
  46.     return 0;
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment