fork download
  1. #include <iostream>
  2. using namespace std;
  3. #include <iostream>
  4. using namespace std;
  5. int i;
  6. int Sommapos=0, Sommaneg=0;
  7. int contapos=0, contaneg=0;
  8. int x;
  9.  
  10.  
  11. int main() {
  12. cin>>i;
  13. for(i>=1;i<=10;i++);
  14.  
  15. { cin>>x;
  16. if (x>0) {Sommapos= Sommapos+x; contapos=contapos +1;}
  17. if (x<0) {Sommaneg= Sommaneg+x; contaneg=contaneg +1;}
  18.  
  19. }
  20.  
  21. if(contapos!=0) { cout<<"Media valori positivi="<<(float)Sommapos/contapos<<endl;}
  22. else {cout<<"Media numeri positivi non calcolabile!!"<<endl;}
  23.  
  24. if(contaneg!=0) { cout<<"Media valori negativi="<<(float)Sommaneg/contaneg<<endl;}
  25. else {cout<<"Media numeri negativi non calcolabile!!"<<endl;}
  26.  
  27. // your code goes here
  28. return 0;
  29. }
Success #stdin #stdout 0.01s 5244KB
stdin
1 2 3 -4 -5 -6 7 8 9 -10
stdout
Media valori positivi=2
Media numeri negativi non calcolabile!!