forked from Arunb-lab1/Hacktoberfest2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrix multiplaction.c
68 lines (56 loc) · 1.4 KB
/
matrix multiplaction.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
65
66
67
68
#include<stdio.h>
#include<stdlib.h>
int main()
{
int m,n,m2,n2,sum=0;
printf("No of coloum of first matrix must be equal to the no. of rows in second matrix\n ");
printf("Enter the number of rows and coloum of your first matrix\n");
scanf("%d %d",&m,&n);
printf("Enter the number of rows and coloum of your first matrix\n");
scanf("%d %d",&m2,&n2);
if(n==m2){
int a[m][n],b[m2][n2],result[m][n2];
printf("Enter your First matrix\n");
for (int i = 0; i<m; i++)
{
for (int j = 0;j<n; j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter your second matrix\n");
for (int i = 0; i<m2; i++)
{
for (int j = 0; j <n2; j++)
{
scanf("%d",&b[i][j]);
}
}
printf("Resultant matrix is\n");
for (int i = 0; i<m; i++)
{
for (int j = 0; j <n2; j++)
{
for (int k = 0; k < n; k++)
{
sum += a[i][k] * b[k][j];
}
result[i][j] = sum;
sum = 0;
}
}
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n2; j++)
{
printf("%d \t", result[i][j]);
}
printf("\n");
}
}
else
{
printf("Multiplication of this matrix is not possible");
}
return 0;
}