-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06-2-2darray-dyn.cpp
More file actions
61 lines (52 loc) · 1.32 KB
/
Copy path06-2-2darray-dyn.cpp
File metadata and controls
61 lines (52 loc) · 1.32 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
55
56
57
58
59
60
61
#include <iostream>
using namespace std;
int main()
{
size_t rows, cols;
cout << "Введите количество строк матрицы: ";
cin >> rows;
cout << "Введите количество столбцов матрицы: ";
cin >> cols;
int **arr = new int *[rows];
for (size_t i = 0; i < rows; i++)
{
arr[i] = new int[cols];
}
int *b = new int[cols];
int *res = new int[rows];
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;
for (size_t i = 0; i < rows; i++)
{
delete[] arr[i];
}
delete[] arr;
delete[] b;
delete[] res;
}