fork download
  1. #include <iostream>
  2. using namespace std;
  3. int A[8]={5, -8, 9,-17,44,-3,2,-9};
  4. int somma=0;
  5. int main() {
  6.  
  7. for (int i=0; i<8; i++)
  8. cout<<A[i]<<"\t";
  9.  
  10. cout<<endl;
  11.  
  12. for (int i=0; i<8; i++)
  13. if (A[i]<0){ somma=somma+A[i]; A[i]=0;}
  14. cout<<"somma= "<<somma<<endl;
  15.  
  16. for (int i=0; i<8; i++)
  17. cout<<A[i]<<"\t";
  18.  
  19. return 0;
  20. }
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
5	-8	9	-17	44	-3	2	-9	
somma= -37
5	0	9	0	44	0	2	0