fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. int tab[3][4] = {{1,2,3,4},{0,2,2,0},{1,5,4,2}};
  7.  
  8. for (int i=0;i<3;i++){
  9. for (int j=0; j<4; j++){
  10. cout << tab[i][j] << " ";
  11. }
  12. cout << endl;
  13. }
  14.  
  15. int suma_wiersza=0;
  16. for (int i=0;i<3;i++){
  17. for (int j=0; j<4; j++){
  18. suma_wiersza += tab[i][j];
  19. }
  20. cout<< "Suma wiersza " << i+1 << " = " << suma_wiersza << endl;
  21. suma_wiersza=0;
  22. }
  23. int suma_kolumny=0;
  24. for (int j=0; j<4; j++)
  25. {
  26. for(int i=0; i<3; i++)
  27. {
  28. suma_kolumny += tab[i][j];
  29. }
  30. cout<< "Suma kolumny " << j+1 << " = " << suma_kolumny << endl;
  31. suma_kolumny=0;
  32. }
  33.  
  34.  
  35.  
  36. return 0;
  37. }
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
1 2 3 4 
0 2 2 0 
1 5 4 2 
Suma wiersza 1 = 10
Suma wiersza 2 = 4
Suma wiersza 3 = 12
Suma kolumny 1 = 2
Suma kolumny 2 = 9
Suma kolumny 3 = 9
Suma kolumny 4 = 6