-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06-1-2darray.cpp
More file actions
54 lines (46 loc) · 1.33 KB
/
Copy path06-1-2darray.cpp
File metadata and controls
54 lines (46 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
using namespace std;
int main()
{
size_t rows, cols;
const size_t MAX_SIZE = 10;
int arr[MAX_SIZE][MAX_SIZE];
int b[MAX_SIZE], res[MAX_SIZE];
cout << "Введите количество строк матрицы: ";
cin >> rows;
cout << "Введите количество столбцов матрицы: ";
cin >> cols;
if (rows > MAX_SIZE || cols > MAX_SIZE)
{
cerr << "Ошибка: ни одна из сторон матрицы не может быть больше " << MAX_SIZE << endl;
return 1;
}
cout << "Введите элементы матрицы arr (построчно через пробел):" << endl;
for (size_t i = 0; i < rows; i++)
{
for (size_t j = 0; j < cols; j++)
{
cin >> arr[i][j];
}
}
cout << "Введите элементы вектора b (через пробел):" << endl;
for (size_t j = 0; j < cols; j++)
{
cin >> b[j];
}
// res = arr * b
for (size_t i = 0; i < rows; i++)
{
res[i] = 0;
for (size_t j = 0; j < cols; j++)
{
res[i] += arr[i][j] * b[j];
}
}
cout << "Вектор res:" << endl;
for (size_t i = 0; i < rows; i++)
{
cout << res[i] << ' ';
}
cout << endl;
}