fork download
  1. #include <iostream>
  2. using namespace std;
  3. int A[4][4];
  4.  
  5.  
  6. int main() {
  7.  
  8. for (int i=0;i<4;i++)
  9. for (int j=0;j<4;j++)
  10. cin>>A[i][j];
  11.  
  12. int Somma=0;
  13. for (int i=0;i<4;i++)
  14. for (int j=0;j<4;j++)
  15. Somma=Somma + A[i][j];
  16.  
  17. cout<<"Somma elementi della matrice = "<<Somma<<endl;
  18.  
  19. Somma=0;
  20. for (int i=0;i<4;i++)
  21. { Somma=0;
  22. for (int j=0;j<4;j++)
  23. Somma=Somma + A[i][j];
  24. cout<<"Somma riga n. "<<i<<" = "<<Somma<<endl;}
  25.  
  26. for (int j=0;j<4;j++)
  27. { Somma=0;
  28. for (int i=0;i<4;i++)
  29. Somma=Somma + A[i][j];
  30. cout<<"Somma colonna n. "<<j<<" = "<<Somma<<endl;}
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41. return 0;
  42. }
Success #stdin #stdout 0.01s 5320KB
stdin
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
stdout
Somma elementi della matrice = 136
Somma riga n.  0 = 10
Somma riga n.  1 = 26
Somma riga n.  2 = 42
Somma riga n.  3 = 58
Somma colonna n.  0 = 28
Somma colonna n.  1 = 32
Somma colonna n.  2 = 36
Somma colonna n.  3 = 40