fork download
  1. #include <iostream>
  2. using namespace std;
  3. /*Dopo aver memorizzato e letto 8 numeri in array,
  4.   calcolare la somma di quelli negativi e memorizzare zero al loro posto*/
  5. int A[8]={5, -8,9,-17,44,-3,2, -9};
  6. int Somma=0;
  7. int main() {
  8.  
  9. for (int i=0; i<8; i++)
  10. cout<<A[i]<<"\t";
  11.  
  12. cout<<endl;
  13. for (int i=0; i<8; i++)
  14. if (A[i]<0){ Somma=Somma+A[i]; A[i]=0;}
  15.  
  16. cout<<"Somma= " <<Somma<<endl;
  17.  
  18. for (int i=0; i<8; i++)
  19. cout<<A[i]<<"\t";
  20.  
  21.  
  22. return 0;
  23. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
5	-8	9	-17	44	-3	2	-9	
Somma= -37
5	0	9	0	44	0	2	0