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