task2.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #include <iostream>
  2. int main() {
  3. int arr[3][4] = {
  4. {3, 5, 6, 7},
  5. {12, 1, 1, 1},
  6. {0, 7, 12, 1}
  7. };
  8. int rowSum1 = 0, rowSum2 = 0, rowSum3 = 0;
  9. int colSum1 = 0, colSum2 = 0, colSum3 = 0, colSum4 = 0;
  10. int totalSum = 0;
  11. for (int i = 0; i < 3; ++i) {
  12. for (int j = 0; j < 4; ++j) {
  13. totalSum += arr[i][j];
  14. if (i == 0) rowSum1 += arr[i][j];
  15. if (i == 1) rowSum2 += arr[i][j];
  16. if (i == 2) rowSum3 += arr[i][j];
  17. if (j == 0) colSum1 += arr[i][j];
  18. if (j == 1) colSum2 += arr[i][j];
  19. if (j == 2) colSum3 += arr[i][j];
  20. if (j == 3) colSum4 += arr[i][j];
  21. }
  22. }
  23. std::cout << arr[0][0] << " " << arr[0][1] << " " << arr[0][2] << " " << arr[0][3] << " | " << rowSum1 << std::endl;
  24. std::cout << arr[1][0] << " " << arr[1][1] << " " << arr[1][2] << " " << arr[1][3] << " | " << rowSum2 << std::endl;
  25. std::cout << arr[2][0] << " " << arr[2][1] << " " << arr[2][2] << " " << arr[2][3] << " | " << rowSum3 << std::endl;
  26. std::cout << "--------------------" << std::endl;
  27. std::cout << colSum1 << " " << colSum2 << " " << colSum3 << " " << colSum4 << " | " << totalSum << std::endl;
  28. return 0;
  29. }