-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage81.cpp
More file actions
36 lines (32 loc) · 835 Bytes
/
Copy pathpage81.cpp
File metadata and controls
36 lines (32 loc) · 835 Bytes
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
#include <iostream>
double* mxvrmy(const double * const * const mx, double* const vr,
int n, int m)
{
double* tmv = new double [n];
for(int i = 0; i < n; i++){
tmv[i] = 0;
for(int j = 0; j < m; j++)
tmv[i] += mx[i][j]*vr[j];
}
return tmv;
}
int main()
{
using namespace std;
int n = 100;
int m = 200;
double** a = new double* [n];
for(int i = 0; i < n; i++) a[i] = new double [m];
double* b = new double [m];
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++) a[i][j] = i*i +j;
for(int j = 0; j < m; j++) b[j] = j;
double* c = mxvrmy(a, b, n, m);
double sum = 0;
for(int j = 0; j < m; j++) sum += c[j];
cout << sum << endl;
for(int i = 0; i < n; i++) delete[] a[i];
delete[] a;
delete[] b;
delete[] c;
}