-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMATRIX.c
More file actions
45 lines (42 loc) · 1.09 KB
/
MATRIX.c
File metadata and controls
45 lines (42 loc) · 1.09 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
// C program that performs the matrix operation D = (A * B) + C
#include <stdio.h>
int main()
{
// define matrices a, b, c;
int A[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int B[3][3] = {{9, 8, 7}, {6, 5, 4}, {3, 2, 1}};
int C[3][3] = {{1, 1, 1}, {1, 1, 1}, {1, 1, 1}};
// define matric d to store the result;
int D[3][3];
// perform matrix operation multiplication (a * b);
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
D[i][j] = 0;
for (int k = 0; k < 3; k++)
{
D[i][j] = D[i][j] + (A[i][k] * B[k][j]);
}
}
}
// Perform matrix addition (D + C)
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
D[i][j] += C[i][j];
}
}
// display the resultant matrix d
printf("result matrix D: \n");
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
printf("%d ", D[i][j]);
}
printf("\n");
}
return 0;
}