-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix_Multiplication.c
More file actions
84 lines (72 loc) · 1.97 KB
/
Matrix_Multiplication.c
File metadata and controls
84 lines (72 loc) · 1.97 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Matrix Multiplication
#include<stdio.h>
int main()
{
int matrix1[100][100], matrix2[100][100], i, j, k, row1, col1, row2, col2, resultant_matrix[100][100], sum;
printf("Enter Row size of 1st Matrix\n");
scanf("%d", &row1);
printf("Enter Column size of 1st Matrix\n");
scanf("%d", &col1);
printf("Enter Row size of 2nd Matrix\n");
scanf("%d", &row2);
printf("Enter Column size of 2nd Matrix\n");
scanf("%d", &col2);
if (col1 != row2)
printf("Matrix Multiplication not possible\n");
else
{
printf("Enter 1st Matrix Elements\n");
for (i = 0; i < row1; i++)
{
for (j = 0; j < col1; j++)
{
scanf("%d", &matrix1[i][j]);
}
}
printf("Enter 2nd Matrix Elements\n");
for (i = 0; i < row2; i++)
{
for (j = 0; j < col2; j++)
{
scanf("%d", &matrix2[i][j]);
}
}
printf("1st Matrix is\n");
for (i = 0; i < row1; i++)
{
for (j = 0; j < col1; j++)
{
printf("%d", matrix1[i][j]);
printf("\t");
}
printf("\n");
}
printf("2nd Matrix is\n");
for (i = 0; i < row2; i++)
{
for (j = 0; j < col2; j++)
{
printf("%d", matrix2[i][j]);
printf("\t");
}
printf("\n");
}
printf("The Resultant Matrix is\n");
for (i = 0; i < row1; i++)
{
for (j = 0; j < col2; j++)
{
sum = 0;
for (k = 0; k < col1 && k < row2; k++)
{
sum += matrix1[i][k] * matrix2[k][j];
}
resultant_matrix[i][j] = sum;
printf("%d", resultant_matrix[i][j]);
printf("\t");
}
printf("\n");
}
}
return 0;
}