orlandoju

ejer1_tp4

Apr 20th, 2022
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1.  
  2. /*1
  3. Hacer un programa para ingresar una lista de números que finaliza cuando se ingresa un cero, luego informar cuántos son positivos y cuántos son negativos.
  4.  
  5. Ejemplo: 4, -3, 8, -5, 18, 20, 0. Se listará Positivos: 4 Negativos: 2.*/
  6.  
  7.  
  8.  
  9.  
  10. #include <iostream>
  11. using namespace std;
  12.  
  13. int main(void){
  14.  
  15.     int i,n;
  16.     int cpos=0;
  17.     int cneg=0;
  18.     do
  19.     {
  20.     cout<< " Ingrese un numero: "<<endl;
  21.          cin>>n;
  22.            
  23.    
  24.        cout<<"--------------------"<<endl;
  25.       if(n>0)
  26.       {
  27.       cpos++;
  28.       }
  29.       else if(n<0)
  30.       {
  31.           cneg++;
  32.       }
  33.          
  34.          
  35.          
  36.     }
  37.    while(n!=0);
  38.    
  39.          
  40.    
  41.       cout<< "Positivos: " << cpos << endl;
  42.       cout<<"Negativos: "<< cneg << endl;
  43.     return 0;
  44. }
  45.  
  46.  
Advertisement
Add Comment
Please, Sign In to add comment