From ddc3793651f3fe9d95b6167fa2f90f7e4106156e Mon Sep 17 00:00:00 2001 From: Misha Date: Tue, 16 Sep 2025 20:35:25 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20elem2.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- elem2.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 elem2.cpp diff --git a/elem2.cpp b/elem2.cpp new file mode 100644 index 0000000..bac5b75 --- /dev/null +++ b/elem2.cpp @@ -0,0 +1,61 @@ +#include + +#define N 3 +#define M 4 + +using namespace std; + + +int main() { + setlocale(0, ""); + srand(time(0)); + + int arr[N][M]{ 0 }; + int i; + int j; + + int sum_r[N]{ 0 }; + int sum_c[M]{ 0 }; + int sum_all = 0; + + + for (i = 0; i < N; ++i) { + for (j = 0; j < M; ++j) { + arr[i][j] = rand() % 55 + 2; + } + } + + cout << "Показати масив (рядки):\n"; + for (i = 0; i < N; ++i) { + for (j = 0; j < M; ++j) { + sum_r[i] += arr[i][j]; + cout.width(4); + cout << arr[i][j]; + } + cout << " | " << sum_r[i] << endl; + } + + for (i = 0; i < M + 2; ++i) { + cout << "----"; + } + cout << endl; + + for (j = 0; j < M; ++j) { + for (i = 0; i < N; ++i) { + sum_c[j] += arr[i][j]; + } + } + + for (i = 0; i < N; ++i) { + sum_all += sum_r[i]; + } + + for (j = 0; j < M; ++j) { + cout.width(4); + cout << sum_c[j]; + } + cout << " | " << sum_all << endl; + + system("pause"); + return 0; +} \ No newline at end of file