-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy path12.c
64 lines (55 loc) · 1.31 KB
/
12.c
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
62
63
64
#include <stdio.h>
void multiply_matrices(int *matrix_one, int *matrix_two, int m, int n)
{
int i, j, k;
int result[m][m];
for (i = 0; i < m; i++)
{
for (j = 0; j < m; j++)
{
result[i][j] = 0;
for (k = 0; k < n; k++)
{
result[i][j] += *(matrix_one + i * n + k) * *(matrix_two + k * m + j);
}
}
}
printf("Resultant matrix: \n");
for (i = 0; i < m; i++)
{
printf("[");
for (j = 0; j < m; j++)
{
printf(" %d ", result[i][j]);
}
printf("]\n");
}
}
int main()
{
int m, n;
printf("Enter m and n (mxn) (nxm): ");
scanf("%d %d", &m, &n);
int matrix_one[m][n];
int matrix_two[n][m];
int i, j;
printf("Enter matrix one elements: \n");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
printf("Enter element at (%d, %d): ", i, j);
scanf("%d", &matrix_one[i][j]);
}
}
printf("Enter matrix two elements: \n");
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
printf("Enter element at (%d, %d): ", i, j);
scanf("%d", &matrix_two[i][j]);
}
}
multiply_matrices((int *)matrix_one, (int *)matrix_two, m, n);
}