-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2darraymultiplication.c
More file actions
61 lines (53 loc) · 1.26 KB
/
Copy path2darraymultiplication.c
File metadata and controls
61 lines (53 loc) · 1.26 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 <stdio.h>
void main()
{
int r1, r2, c1, c2, i, j, k;
do
{
printf("Enter number of rows and columns for first matrix:");
scanf("%d%d", &r1, &c1);
printf("Enter number of rows and columns for second matrix:");
scanf("%d%d", &r2, &c2);
if (c1 != r2)
{
printf("Invalid configuration.\n");
}
} while (c1 != r2);
int a[r1][c1], b[r2][c2], c[r1][c2];
for (i = 0; i < r1; i++)
{
for (j = 0; j < c1; j++)
{
printf("Enter the value for a%d%d:", i + 1, j + 1);
scanf("%d", &a[i][j]);
}
}
for (i = 0; i < r2; i++)
{
for (j = 0; j < c2; j++)
{
printf("Enter the value for b%d%d:", i + 1, j + 1);
scanf("%d", &b[i][j]);
}
}
for (i = 0; i < r1; i++)
{
for (j = 0; j < c2; j++)
{
c[i][j] = 0;
for (k = 0; k < c1; k++)
{
c[i][j] = c[i][j] + a[i][k] * b[k][j];
}
}
}
printf("The required multiplication of matrix a and b is:\n");
for (i = 0; i < c2; i++)
{
for (j = 0; j < r1; j++)
{
printf("%d\t", c[i][j]);
}
printf("\n");
}
}