-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrixMultiplySequential.c
More file actions
52 lines (44 loc) · 1.01 KB
/
MatrixMultiplySequential.c
File metadata and controls
52 lines (44 loc) · 1.01 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
/* PROGRAM MatrixMultiplySequential */
#include <stdlib.h>
#include <math.h>
#define n 10
float A[n+1][n+1], B[n+1][n+1], C[n+1][n+1];
int i, j;
void VectorProduct(int i, int j) {
float sum;
int k;
sum = 0;
for (k = 1; k <= n; k++)
sum = sum + A[i][k]*B[k][j];
C[i][j] = sum;
}
void printMatrix(float p[n+1][n+1]) {
int l, m;
for (l = 1; l <= n; l++) {
for (m = 1; m <= n; m++)
cout << p[l][m] << " ";
cout << "\n";
}
cout << "\n";
}
main() {
cout.precision(8); /* use 8 significant digits for float output */
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++) {
a[i][j] = (rand() % 10000)/100.0;
b[i][j] = (rand() % 10000)/100.0;
}
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++)
/*compute row i of A times column j of B*/
VectorProduct(i, j);
cout << "A = " << "\n";
printMatrix(A);
cout << "\n";
cout << "B = " << "\n";
printMatrix(B);
cout << "\n";
cout << "C = " << "\n";
printMatrix(C);
cout << "\n";
}