-
Notifications
You must be signed in to change notification settings - Fork 3
/
P-71.c
52 lines (52 loc) · 1 KB
/
P-71.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
//Write a c program to multiply two 2-D array.
#include <stdio.h>
int main()
{
int r,c;
int matrix1[100][100];
int matrix2[100][100];
int result[100][100];
int i, j, k;
printf("Enter the number of rows: ");
scanf("%d", &r);
printf("Enter the number of columns: ");
scanf("%d", &c);
printf("Enter elements of the first matrix:\n");
for (i = 0; i < r; i++)
{
for (j = 0; j < c; j++)
{
printf("Enter the element in row-%d and column-%d :",i,j);
scanf("%d", &matrix1[i][j]);
}
}
printf("Enter elements of the second 2x2 matrix:\n");
for (i = 0; i < r; i++)
{
for (j = 0; j < c; j++)
{
printf("Enter the element in row-%d and column-%d :",i,j);
scanf("%d", &matrix2[i][j]);
}
}
for (i = 0; i < r; i++)
{
for (j = 0; j < c; j++)
{
result[i][j] = 0;
for (k = 0; k < 2; k++)
{
result[i][j] += matrix1[i][k] * matrix2[k][j];
}
}
}
printf("Result of matrix multiplication:\n");
for (i = 0; i < r; i++)
{
for (j = 0; j < c; j++)
{
printf("%d ", result[i][j]);
}
printf("\n");
}
}